Commit 82e40daf authored by campaign's avatar campaign

改变光标策略适应拖拽策略

parent f073a7f3
......@@ -82,7 +82,7 @@ KityMinder.registerModule('TextEditModule', function() {
if (this.isSingleSelect() && node.isSelected() && hasCursor) {
sel.collapse();
sel.setSelectionShowStatus(true);
node.getRenderer('TextRenderer').getRenderShape().setStyle('cursor', 'text');
receiver.setTextEditStatus(true)
......@@ -114,69 +114,69 @@ KityMinder.registerModule('TextEditModule', function() {
}
},
//当输入键值是内容时,进入textedit状态
'normal.beforekeydown': function(e) {
var node = this.getSelectedNode();
if (node) {
if (this.isSingleSelect() && node.isSelected()) {
var orgEvt = e.originEvent,
keyCode = orgEvt.keyCode;
if (!keymap.notContentInput[keyCode] &&
range.nativeSel.rangeCount !== 0 &&
!orgEvt.ctrlKey && !orgEvt.metaKey &&
!orgEvt.shiftKey && !orgEvt.altKey) {
var nativeRange = range.nativeSel.getRangeAt(0);
if (nativeRange && (nativeRange.startContainer === receiver.container ||
receiver.container.contains(nativeRange.startContainer))) {
km.setStatus('textedit');
sel.setSelectionShowStatus(true);
km.fire('saveScene');
}
}
}
}
},
//当节点选区通过键盘发生变化时,输入状态要准备好
'normal.keyup': function(e) {
var node = this.getSelectedNode();
if (node) {
if (this.isSingleSelect() && node.isSelected()) {
var orgEvt = e.originEvent,
keyCode = orgEvt.keyCode;
if (keymap.isSelectedNodeKey[keyCode] &&
km.getStatus() != 'textedit' &&
!orgEvt.ctrlKey &&
!orgEvt.metaKey &&
!orgEvt.shiftKey &&
!orgEvt.altKey) {
//准备输入状态
var textShape = node.getRenderer('TextRenderer').getRenderShape();
sel.setHide();
sel.setStartOffset(0);
sel.setEndOffset(textShape.getContent().length);
sel.setSelectionShowStatus(true);
receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
.setMinderNode(node)
.setTextShape(textShape)
.setRange(range)
.setBaseOffset()
.setContainerStyle()
.setSelectionHeight()
.setContainerTxt(textShape.getContent())
.updateRange(range).setTextEditStatus(true);
sel.setData('relatedNode', node);
}
}
}
},
// //当输入键值是内容时,进入textedit状态
// 'normal.beforekeydown': function(e) {
// var node = this.getSelectedNode();
// if (node) {
// if (this.isSingleSelect() && node.isSelected()) {
// var orgEvt = e.originEvent,
// keyCode = orgEvt.keyCode;
// if (!keymap.notContentInput[keyCode] &&
// range.nativeSel.rangeCount !== 0 &&
// !orgEvt.ctrlKey && !orgEvt.metaKey &&
// !orgEvt.shiftKey && !orgEvt.altKey) {
//
// var nativeRange = range.nativeSel.getRangeAt(0);
// if (nativeRange && (nativeRange.startContainer === receiver.container ||
// receiver.container.contains(nativeRange.startContainer))) {
// km.setStatus('textedit');
// sel.setSelectionShowStatus(true);
// km.fire('saveScene');
// }
//
// }
// }
// }
// },
// //当节点选区通过键盘发生变化时,输入状态要准备好
// 'normal.keyup': function(e) {
// var node = this.getSelectedNode();
// if (node) {
// if (this.isSingleSelect() && node.isSelected()) {
// var orgEvt = e.originEvent,
// keyCode = orgEvt.keyCode;
// if (keymap.isSelectedNodeKey[keyCode] &&
// km.getStatus() != 'textedit' &&
// !orgEvt.ctrlKey &&
// !orgEvt.metaKey &&
// !orgEvt.shiftKey &&
// !orgEvt.altKey) {
//
// //准备输入状态
// var textShape = node.getRenderer('TextRenderer').getRenderShape();
//
// sel.setHide();
// sel.setStartOffset(0);
// sel.setEndOffset(textShape.getContent().length);
// sel.setSelectionShowStatus(true);
// receiver.setTextEditStatus(true)
// .setSelection(sel)
// .setKityMinder(this)
// .setMinderNode(node)
// .setTextShape(textShape)
// .setRange(range)
// .setBaseOffset()
// .setContainerStyle()
// .setSelectionHeight()
// .setContainerTxt(textShape.getContent())
// .updateRange(range).setTextEditStatus(true);
//
// sel.setData('relatedNode', node);
// }
// }
// }
// },
'normal.mouseup textedit.mouseup': function(e) {
var node = e.getTargetNode();
......@@ -185,9 +185,8 @@ KityMinder.registerModule('TextEditModule', function() {
var textShape = node.getRenderer('TextRenderer').getRenderShape();
if (isSelected && !hasCursor) {
console.log('sd')
sel.collapse();
sel.setSelectionShowStatus(true);
node.getRenderer('TextRenderer').getRenderShape().setStyle('cursor', 'text');
receiver.setTextEditStatus(true)
......@@ -306,7 +305,7 @@ KityMinder.registerModule('TextEditModule', function() {
sel.setHide();
sel.setStartOffset(0);
sel.setEndOffset(textShape.getContent().length);
sel.setSelectionShowStatus(false);
receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
......
......@@ -33,7 +33,7 @@ Minder.Receiver = kity.createClass('Receiver', {
});
}
utils.addCssRule('km_receiver_css', ' .km_receiver{white-space:nowrap;position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);'); //
this.km.on('textedit.beforekeyup textedit.keydown textedit.keypress textedit.paste', utils.proxy(this.keyboardEvents, this));
this.km.on('textedit.beforekeyup textedit.beforekeydown textedit.keypress textedit.paste', utils.proxy(this.keyboardEvents, this));
this.timer = null;
this.index = 0;
},
......@@ -105,7 +105,12 @@ Minder.Receiver = kity.createClass('Receiver', {
me.minderNode.setText('a');
}
me.setContainerStyle();
me.minderNode.render().layout();
me.minderNode.getRenderContainer().bringTop();
me.minderNode.render();
clearTimeout(me.inputTextTimer);
me.inputTextTimer = setTimeout(function(){
me.km.layout(300);
},250);
me.textShape = me.minderNode.getRenderer('TextRenderer').getRenderShape();
if (text.length === 0) {
......@@ -116,13 +121,10 @@ Minder.Receiver = kity.createClass('Receiver', {
me.updateIndex();
if (me.selection.getSelectionShowStatus()) {
me.updateSelection();
me.timer = setTimeout(function() {
me.selection.setShow();
}, 500);
}
}, 300);
}
......@@ -137,16 +139,18 @@ Minder.Receiver = kity.createClass('Receiver', {
}
break;
case 'keydown':
case 'beforekeydown':
this.isTypeText = keyCode == 229 || keyCode === 0;
switch (keyCode) {
case keys.Enter:
case keys.Tab:
this.selection.setHide();
case keymap.Enter:
case keymap.Tab:
if(this.selection.isShow()){
this.clear().setTextEditStatus(false);
this.km.fire('contentchange');
this.km.setStatus('normal');
e.preventDefault();
}else{
this.km.setStatus('normal');
this.km.fire('contentchange');
}
return;
case keymap.Shift:
case keymap.Control:
......@@ -189,6 +193,7 @@ Minder.Receiver = kity.createClass('Receiver', {
case keymap.F2:
if (keymap.Enter == keyCode && (this.isTypeText || browser.mac && browser.gecko)) {
setTextToContainer();
}
if (this.keydownNode === this.minderNode) {
this.rollbackStatus();
......@@ -203,7 +208,6 @@ Minder.Receiver = kity.createClass('Receiver', {
setTextToContainer();
return;
}
if (this.isTypeText) {
setTextToContainer();
}
......@@ -248,12 +252,7 @@ Minder.Receiver = kity.createClass('Receiver', {
return this;
},
getBaseOffset: function(refer) {
var rb = this.textShape.getRenderBox(refer || this.km.getRenderContainer());
// if(!this.pr) {
// this.km.getRenderContainer().addShape(this.pr = new kity.Rect().stroke('green'));
// }
// this.pr.setSize(rb.width, rb.height).setPosition(rb.x, rb.y);
return rb;
return this.textShape.getRenderBox(refer || this.km.getRenderContainer());
},
setBaseOffset: function() {
this.offset = this.textShape.getRenderBox(this.km.getRenderContainer());
......
......@@ -104,7 +104,6 @@ Minder.Selection = kity.createClass( 'Selection', {
var me = this,
state = '';
me.setStyle( 'display', '' );
this.setSelectionShowStatus(true);
me._show = true;
if(this.collapsed){
me.setOpacity(1);
......@@ -132,14 +131,5 @@ Minder.Selection = kity.createClass( 'Selection', {
},
setTxtContent: function ( text ) {
this.text.setContent( text );
},
updatePosition: function ( index ) {
},
setSelectionShowStatus:function(status){
this.selectionShowStatus = status;
},
getSelectionShowStatus:function(){
return this.selectionShowStatus;
}
} );
\ No newline at end of file
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