Commit 7862e551 authored by Akikonata's avatar Akikonata

Merge branch 'dev' of https://github.com/fex-team/kityminder into dev

parents effcf515 5dc8b28e
# KityMinder Change List
## 1.1.0
### 功能更新
1. 添加了粘贴剪贴复制功能
### 问题修复
...@@ -35,7 +35,10 @@ var keymap = KityMinder.keymap = { ...@@ -35,7 +35,10 @@ var keymap = KityMinder.keymap = {
"b":66, "b":66,
'i':73, 'i':73,
//回退
'z':90, 'z':90,
'y':89 'y':89,
//粘贴
'v' : 86,
'x' : 88
}; };
\ No newline at end of file
...@@ -21,7 +21,7 @@ kity.extendClass( Minder, { ...@@ -21,7 +21,7 @@ kity.extendClass( Minder, {
_bindKeyboardEvents: function () { _bindKeyboardEvents: function () {
if ( ( navigator.userAgent.indexOf( 'iPhone' ) == -1 ) && ( navigator.userAgent.indexOf( 'iPod' ) == -1 ) && ( navigator.userAgent.indexOf( 'iPad' ) == -1 ) ) { if ( ( navigator.userAgent.indexOf( 'iPhone' ) == -1 ) && ( navigator.userAgent.indexOf( 'iPod' ) == -1 ) && ( navigator.userAgent.indexOf( 'iPad' ) == -1 ) ) {
//只能在这里做,要不无法触发 //只能在这里做,要不无法触发
Utils.listen( document.body, 'keydown keyup keypress', this._firePharse.bind( this ) ); Utils.listen( document.body, 'keydown keyup keypress paste', this._firePharse.bind( this ) );
} }
}, },
_firePharse: function ( e ) { _firePharse: function ( e ) {
......
...@@ -35,6 +35,7 @@ Minder.Range = kity.createClass('Range',{ ...@@ -35,6 +35,7 @@ Minder.Range = kity.createClass('Range',{
startOffset:range.startOffset startOffset:range.startOffset
} }
}, },
collapse:function(toStart){ collapse:function(toStart){
this.nativeRange.collapse(toStart === true); this.nativeRange.collapse(toStart === true);
return this; return this;
...@@ -42,5 +43,10 @@ Minder.Range = kity.createClass('Range',{ ...@@ -42,5 +43,10 @@ Minder.Range = kity.createClass('Range',{
insertNode:function(node){ insertNode:function(node){
this.nativeRange.insertNode(node); this.nativeRange.insertNode(node);
return this; return this;
},
updateNativeRange:function(){
this.nativeRange = this.nativeSel.getRangeAt(0);
return this;
} }
}); });
\ No newline at end of file
...@@ -5,6 +5,7 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -5,6 +5,7 @@ Minder.Receiver = kity.createClass('Receiver',{
this.selection && this.selection.setHide(); this.selection && this.selection.setHide();
this.range && this.range.nativeSel.removeAllRanges(); this.range && this.range.nativeSel.removeAllRanges();
this.index = 0; this.index = 0;
this.inputLength = 0;
return this; return this;
}, },
setTextEditStatus : function(status){ setTextEditStatus : function(status){
...@@ -21,8 +22,8 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -21,8 +22,8 @@ Minder.Receiver = kity.createClass('Receiver',{
_div.setAttribute('contenteditable',true); _div.setAttribute('contenteditable',true);
_div.className = 'km_receiver'; _div.className = 'km_receiver';
this.container = document.body.insertBefore(_div,document.body.firstChild); this.container = document.body.insertBefore(_div,document.body.firstChild);
utils.addCssRule('km_receiver_css',' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}');// utils.addCssRule('km_receiver_css',' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;}');//clip:rect(1em 1em 1em 1em);
this.km.on('textedit.beforekeyup textedit.keydown', utils.proxy(this.keyboardEvents,this)); this.km.on('textedit.beforekeyup textedit.keydown textedit.paste', utils.proxy(this.keyboardEvents,this));
this.timer = null; this.timer = null;
this.index = 0; this.index = 0;
}, },
...@@ -74,8 +75,32 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -74,8 +75,32 @@ Minder.Receiver = kity.createClass('Receiver',{
var orgEvt = e.originEvent; var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode; var keyCode = orgEvt.keyCode;
var keys = KityMinder.keymap; var keys = KityMinder.keymap;
function setTextToContainer(){
var text = me.container.textContent.replace(/[\u200b\t\r\n]/g,'');
if(me.textShape.getOpacity() == 0){
me.textShape.setOpacity(1);
}
me.textShape.setContent(text);
me.setContainerStyle();
me.minderNode.setText(text);
if(text.length == 0){
me.textShape.setContent('a');
me.textShape.setOpacity(0);
}
me.km.updateLayout(me.minderNode);
me.setBaseOffset();
me.updateTextData();
me.updateIndex();
me.updateSelection();
me.timer = setTimeout(function(){
me.selection.setShow()
},500);
}
switch(e.type){ switch(e.type){
case 'keydown': case 'keydown':
switch ( e.originEvent.keyCode ) { switch ( e.originEvent.keyCode ) {
case keys.Enter: case keys.Enter:
...@@ -86,8 +111,33 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -86,8 +111,33 @@ Minder.Receiver = kity.createClass('Receiver',{
e.preventDefault(); e.preventDefault();
break; break;
} }
if ( e.originEvent.ctrlKey || e.originEvent.metaKey ){
//粘贴
if(keyCode == keymap.v){
setTimeout(function(){
me.range.updateNativeRange().insertNode($('<span>$$_kityminder_bookmark_$$</span>')[0]);
me.container.innerHTML = me.container.textContent.replace(/[\u200b\t\r\n]/g,'');
var index = me.container.textContent.indexOf('$$_kityminder_bookmark_$$');
me.container.textContent = me.container.textContent.replace('$$_kityminder_bookmark_$$','');
me.range.setStart(me.container.firstChild,index).collapse(true).select();
setTextToContainer()
},100);
}
//剪切
if(keyCode == keymap.x){
setTimeout(function(){
setTextToContainer()
},100);
}
return;
}
break; break;
case 'beforekeyup': case 'beforekeyup':
switch(keyCode){ switch(keyCode){
case keymap.Enter: case keymap.Enter:
case keymap.Tab: case keymap.Tab:
...@@ -105,34 +155,14 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -105,34 +155,14 @@ Minder.Receiver = kity.createClass('Receiver',{
return; return;
} }
var text = this.container.textContent.replace(/\u200b/g,'');
if(this.textShape.getOpacity() == 0){
this.textShape.setOpacity(1);
}
this.textShape.setContent(text);
this.setContainerStyle();
this.minderNode.setText(text);
if(text.length == 0){
this.textShape.setContent('a');
this.textShape.setOpacity(0);
}
this.km.updateLayout(this.minderNode);
this.setBaseOffset();
this.updateTextData();
this.updateIndex();
this.updateSelection();
this.timer = setTimeout(function(){ setTextToContainer();
me.selection.setShow()
},500);
return true; return true;
} }
}, },
updateIndex:function(){ updateIndex:function(){
this.index = this.range.getStart().startOffset; this.index = this.range.getStart().startOffset;
}, },
......
...@@ -101,6 +101,9 @@ KityMinder.registerModule( "Select", function () { ...@@ -101,6 +101,9 @@ KityMinder.registerModule( "Select", function () {
if ( !downNode ) { if ( !downNode ) {
this.removeAllSelectedNodes(); this.removeAllSelectedNodes();
marqueeActivator.selectStart( e ); marqueeActivator.selectStart( e );
if(this.getStatus() == 'textedit'){
this.trigger('contentchange')
}
this.setStatus('normal') this.setStatus('normal')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment