Commit 82e40daf authored by campaign's avatar campaign

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

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