Commit 1147ff8b authored by campaign's avatar campaign

by zhanyi

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