Commit 1147ff8b authored by campaign's avatar campaign

by zhanyi

parent 7c060bf0
...@@ -42,12 +42,18 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -42,12 +42,18 @@ KityMinder.registerModule( "TextEditModule", function () {
} }
}, },
'mouseup':function(e){ 'mouseup':function(e){
if(!sel.collapsed){
receiver.updateRange(range)
}
mouseDownStatus = false; mouseDownStatus = false;
oneTime = 0; oneTime = 0;
}, },
'mousemove':function(e){ 'mousemove':function(e){
setTimeout(function(){
if(mouseDownStatus){ if(mouseDownStatus){
var offset = e.getPosition(); var offset = e.getPosition();
dir = offset.x > lastEvtPosition.x ? 1 : (offset.x < lastEvtPosition.x ? -1 : dir); dir = offset.x > lastEvtPosition.x ? 1 : (offset.x < lastEvtPosition.x ? -1 : dir);
receiver.updateSelectionByMousePosition(offset,dir) receiver.updateSelectionByMousePosition(offset,dir)
...@@ -55,6 +61,8 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -55,6 +61,8 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.stroke('none',0); sel.stroke('none',0);
lastEvtPosition = e.getPosition(); lastEvtPosition = e.getPosition();
} }
},100)
}, },
'restoreScene':function(){ 'restoreScene':function(){
sel.setHide(); sel.setHide();
......
...@@ -205,55 +205,42 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -205,55 +205,42 @@ Minder.Receiver = kity.createClass('Receiver',{
this.selection.setHeight(this.getTextShapeHeight()); this.selection.setHeight(this.getTextShapeHeight());
return this; return this;
}, },
getIndexByMousePosition:function(offset,dir){
updateSelectionByMousePosition:function(offset,dir){
var me = this; var me = this;
var currentIndex;
var hadChanged = false;
utils.each(this.textData,function(i,v){ utils.each(this.textData,function(i,v){
//点击开始之前 //点击开始之前
if(i == 0 && offset.x <= v.x){ if(i == 0 && offset.x <= v.x){
currentIndex = 0; me.selection.setStartOffset(0);
return false; return false;
} }
if(i == me.textData.length -1 && offset.x >= v.x){ if(i == me.textData.length -1 && offset.x >= v.x){
currentIndex = me.textData.length; me.selection.setEndOffset(me.textData.length);
return false; return false;
} }
if(offset.x >= v.x && offset.x <= v.x + v.width){ if(offset.x >= v.x && offset.x <= v.x + v.width){
currentIndex = i + (dir == -1 ? 0 : 1);
return false;
}
});
return currentIndex;
},
updateSelectionByMousePosition:function(offset,dir){
var currentIndex = this.getIndexByMousePosition(offset,dir); if(me.index == i){
me.selection.setEndOffset(i + (dir == 1 ? 1 : 0))
if(currentIndex == 0){ }else if(i > me.index){
this.selection.setStartOffset(0) me.selection.setEndOffset(i + (dir == 1 ? 1 : 0))
}else if(currentIndex == this.textData.length){
this.selection.setEndOffset(currentIndex)
}else{
if(currentIndex > this.index){
this.selection.setEndOffset(currentIndex)
}else if(currentIndex < this.index){
this.selection.setStartOffset(currentIndex)
}else{ }else{
this.selection.collapse() me.selection.setStartOffset(i + (dir == 1 ? 1 : 0))
}
} }
return false;
}
});
return this; return this;
}, },
updateSelectionShow:function(dir){ updateSelectionShow:function(){
var startOffset = this.textData[this.selection.startOffset], var startOffset = this.textData[this.selection.startOffset],
endOffset = this.textData[this.selection.endOffset], endOffset = this.textData[this.selection.endOffset],
width = 0 ; width = 0 ;
if(this.selection.isCollapsed){ if(this.selection.collapsed){
this.selection.updateShow(startOffset,0); this.selection.updateShow(startOffset,0);
return this; return this;
...@@ -268,7 +255,11 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -268,7 +255,11 @@ Minder.Receiver = kity.createClass('Receiver',{
this.selection.updateShow(startOffset,width); this.selection.updateShow(startOffset,width);
return this; return this;
}, },
updateNativeRange:function(){ updateRange:function(range){
var node = this.container.firstChild;
range.setStart(node,this.selection.startOffset);
range.setEnd(node,this.selection.endOffset);
range.select();
return this;
} }
}); });
\ No newline at end of file
...@@ -10,7 +10,7 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -10,7 +10,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this.fill('#99C8FF'); this.fill('#99C8FF');
this.setHide(); this.setHide();
this.timer = null; this.timer = null;
this.isCollapsed = true; this.collapsed = true;
this.startOffset = this.endOffset = 0; this.startOffset = this.endOffset = 0;
this.setOpacity(0.5) this.setOpacity(0.5)
}, },
...@@ -18,7 +18,7 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -18,7 +18,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this.stroke( 'blue', 1 ); this.stroke( 'blue', 1 );
this.width = 1; this.width = 1;
this.isCollapsed = true; this.collapsed = true;
if(toEnd){ if(toEnd){
this.startOffset = this.endOffset this.startOffset = this.endOffset
}else{ }else{
...@@ -36,7 +36,7 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -36,7 +36,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this.collapse(); this.collapse();
return this; return this;
} }
this.isCollapsed = false; this.collapsed = false;
this.stroke('none'); this.stroke('none');
return this; return this;
}, },
...@@ -50,7 +50,7 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -50,7 +50,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this.collapse(); this.collapse();
return this; return this;
} }
this.isCollapsed = false; this.collapsed = false;
this.stroke('none'); this.stroke('none');
return this; return this;
}, },
......
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