Commit 73960471 authored by campaign's avatar campaign

修复光标的方向键问题

parent 46595032
......@@ -26,11 +26,18 @@ var keymap = KityMinder.keymap = (function(origin) {
'End': 35,
'Home': 36,
'Left': 37,
'Up': 38,
'Right': 39,
'Down': 40,
'direction':{
37:1,
38:1,
39:1,
40:1
},
'Insert': 45,
'Del': 46,
......
......@@ -139,7 +139,6 @@ KityMinder.registerModule('TextEditModule', function() {
if (node && !selectionReadyShow && receiver.isReady()) {
sel.collapse();
sel.setColor(node.getStyle('text-selection-color'));
......@@ -159,10 +158,14 @@ KityMinder.registerModule('TextEditModule', function() {
//当选中节点后,输入状态准备
if(sel.isHide()){
inputStatusReady(e.getTargetNode());
}else {
//当有光标时,要同步选区
receiver.updateContainerRangeBySel();
}
},
'textedit.beforemousemove inputready.beforemousemove': function(e) {
if(browser.ipad){
......@@ -240,9 +243,9 @@ KityMinder.registerModule('TextEditModule', function() {
km.setStatus('normal');
receiver.clear();
},
// 'blur': function() {
// receiver.clear();
// },
'blur': function() {
receiver.clear();
},
'import': function() {
km.setStatus('normal');
receiver.clear();
......
......@@ -162,10 +162,6 @@ Minder.Receiver = kity.createClass('Receiver', {
switch (keyCode) {
case keymap.Enter:
case keymap.Tab:
case keymap.left:
case keymap.right:
case keymap.up:
case keymap.down:
if(this.selection.isShow()){
this.clear();
this.km.setStatus('inputready');
......@@ -176,7 +172,16 @@ Minder.Receiver = kity.createClass('Receiver', {
this.km.fire('contentchange');
}
return;
case keymap.Shift:
case keymap.left:
case keymap.right:
case keymap.up:
case keymap.down:
if(this.selection.isHide()){
this.km.setStatus('normal');
return;
}
break;
// case keymap.Shift:
case keymap.Control:
case keymap.Alt:
case keymap.Cmd:
......@@ -188,7 +193,40 @@ Minder.Receiver = kity.createClass('Receiver', {
}
return;
}
//针对按住shift+方向键进行处理
if(orgEvt.shiftKey && keymap.direction[keyCode] && this.selection.isShow()){
var textlength = this.textShape.getContent().length;
if(keymap.right == keyCode ){
var endOffset = this.selection.endOffset+1;
if(endOffset > textlength){
endOffset = textlength;
}
this.selection.setEndOffset(endOffset);
}else if(keymap.left == keyCode){
endOffset = this.selection.endOffset-1;
if(endOffset < 0){
endOffset = 0;
}
if(endOffset <= this.selection.startOffset){
if(endOffset == this.selection.startOffset){
this.selection.setEndOffset(endOffset)
}else{
this.selection.setStartOffset(endOffset)
}
}else{
this.selection.setEndOffset(endOffset);
}
}
this.updateContainerRangeBySel();
this.updateSelectionShow();
e.preventDefault();
return;
}
if (e.originEvent.ctrlKey || e.originEvent.metaKey) {
//粘贴
......@@ -291,7 +329,7 @@ Minder.Receiver = kity.createClass('Receiver', {
setContainerStyle: function() {
var textShapeBox = this.getBaseOffset('paper');
this.container.style.cssText = ';left:' + (browser.ipad ? '-' : '') +
textShapeBox.x + 'px;top:' + (textShapeBox.y + textShapeBox.height * 0.1) +
textShapeBox.x + 'px;top:' + (textShapeBox.y + textShapeBox.height * 0.1 ) +
'px;width:' + textShapeBox.width + 'px;height:' + textShapeBox.height + 'px;';
if (!this.selection.isShow()) {
......
......@@ -5,8 +5,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this.callBase();
this.height = height || 20;
this.setAttr('id','_kity_selection');
this.stroke( color || 'rgb(27,171,255)', width || 1 );
this.width = 0;
this.width = 2;
this.fill('rgb(27,171,255)');
this.setHide();
this.timer = null;
......@@ -18,14 +17,11 @@ Minder.Selection = kity.createClass( 'Selection', {
},
setColor:function(color){
this.stroke(color);
this.fill(color);
},
collapse : function(toEnd){
// this.stroke( 'rgb(27,171,255)', 1 );
this.setOpacity(1);
this.width = 1;
this.width = 2;
this.collapsed = true;
if(toEnd){
this.startOffset = this.endOffset;
......@@ -45,7 +41,6 @@ Minder.Selection = kity.createClass( 'Selection', {
return this;
}
this.collapsed = false;
this.stroke('none',0);
this.setOpacity(0.5);
return this;
},
......@@ -60,7 +55,7 @@ Minder.Selection = kity.createClass( 'Selection', {
return this;
}
this.collapsed = false;
this.stroke('none',0);
// this.stroke('none',0);
this.setOpacity(0.5);
return this;
},
......@@ -69,19 +64,13 @@ Minder.Selection = kity.createClass( 'Selection', {
this.setShowHold();
}
this.setPosition(offset).setWidth(width);
//解决在框选内容时,出现很窄的光标
if(width === 0){
this.setOpacity(0);
}else{
this.setOpacity(0.5);
}
this.bringTop();
return this;
},
setPosition: function ( offset ) {
try {
this.x = offset.x;
this.y = offset.y;
this.x = Math.round(offset.x);
this.y = Math.round(offset.y);
} catch ( e ) {
console.log(e);
......
......@@ -45,6 +45,7 @@ KityMinder.registerModule( "pasteModule", function () {
break;
case keys.x:
getNodes(km.getSelectedAncestors(),true);
km.layout(300);
_curstatus = true;
break;
case keys.v:
......
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