Commit 3f1a7e78 authored by campaign's avatar campaign

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

parent 486dccd6
...@@ -153,6 +153,7 @@ var TreeDragger = kity.createClass('TreeDragger', { ...@@ -153,6 +153,7 @@ var TreeDragger = kity.createClass('TreeDragger', {
this._renderOrderHint(null); this._renderOrderHint(null);
} }
this._leaveDragMode(); this._leaveDragMode();
this._minder.fire('treedragend');
}, },
// 进入拖放模式: // 进入拖放模式:
...@@ -326,7 +327,7 @@ KityMinder.registerModule('DragTree', function() { ...@@ -326,7 +327,7 @@ KityMinder.registerModule('DragTree', function() {
dragger = new TreeDragger(this); dragger = new TreeDragger(this);
}, },
events: { events: {
mousedown: function(e) { 'mousedown': function(e) {
// 单选中根节点也不触发拖拽 // 单选中根节点也不触发拖拽
if (e.getTargetNode() && e.getTargetNode() != this.getRoot()) { if (e.getTargetNode() && e.getTargetNode() != this.getRoot()) {
dragger.dragStart(e.getPosition(this.getRenderContainer())); dragger.dragStart(e.getPosition(this.getRenderContainer()));
......
...@@ -45,6 +45,9 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -45,6 +45,9 @@ KityMinder.registerModule('TextEditModule', function() {
}; };
var selectionByClick = false; var selectionByClick = false;
var hasCursor = false;
var isSelected = false;
return { return {
'events': { 'events': {
...@@ -58,6 +61,7 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -58,6 +61,7 @@ KityMinder.registerModule('TextEditModule', function() {
e.stopPropagationImmediately(); e.stopPropagationImmediately();
return; return;
} }
hasCursor = sel.isShow();
sel.setHide(); sel.setHide();
var node = e.getTargetNode(); var node = e.getTargetNode();
...@@ -75,12 +79,12 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -75,12 +79,12 @@ KityMinder.registerModule('TextEditModule', function() {
if (node) { if (node) {
var textShape = node.getRenderer('TextRenderer').getRenderShape(); var textShape = node.getRenderer('TextRenderer').getRenderShape();
textShape.setStyle('cursor', 'default'); textShape.setStyle('cursor', 'default');
if (this.isSingleSelect() && node.isSelected()) { if (this.isSingleSelect() && node.isSelected() && hasCursor) {
sel.collapse(); sel.collapse();
sel.setSelectionShowStatus(true); sel.setSelectionShowStatus(true);
node.getRenderer('TextRenderer').getRenderShape().setStyle('cursor', 'text'); node.getRenderer('TextRenderer').getRenderShape().setStyle('cursor', 'text');
km.setStatus('textedit');
receiver.setTextEditStatus(true) receiver.setTextEditStatus(true)
.setSelection(sel) .setSelection(sel)
.setKityMinder(this) .setKityMinder(this)
...@@ -90,17 +94,23 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -90,17 +94,23 @@ KityMinder.registerModule('TextEditModule', function() {
.setContainerStyle() .setContainerStyle()
.setSelectionHeight() .setSelectionHeight()
.setCurrentIndex(e.getPosition(this.getRenderContainer())) .setCurrentIndex(e.getPosition(this.getRenderContainer()))
.updateSelection()
.setRange(range); .setRange(range);
sel.setData('relatedNode', node); sel.setData('relatedNode', node);
mouseDownStatus = true; mouseDownStatus = true;
lastEvtPosition = e.getPosition(this.getRenderContainer()); lastEvtPosition = e.getPosition(this.getRenderContainer());
if (selectionByClick) { if (selectionByClick) {
receiver.updateSelection();
sel.setShow(); sel.setShow();
selectionByClick = false; selectionByClick = false;
}
km.setStatus('textedit'); km.setStatus('textedit');
} }
}
isSelected = node.isSelected();
} }
}, },
...@@ -168,6 +178,41 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -168,6 +178,41 @@ KityMinder.registerModule('TextEditModule', function() {
} }
}, },
'normal.mouseup textedit.mouseup': function(e) { 'normal.mouseup textedit.mouseup': function(e) {
var node = e.getTargetNode();
if (node) {
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)
.setSelection(sel)
.setKityMinder(this)
.setMinderNode(node)
.setTextShape(textShape)
.setBaseOffset()
.setContainerStyle()
.setSelectionHeight()
.setCurrentIndex(e.getPosition(this.getRenderContainer()))
.updateSelection()
.setRange(range);
sel.setData('relatedNode', node);
lastEvtPosition = e.getPosition(this.getRenderContainer());
if (selectionByClick) {
sel.setShow();
selectionByClick = false;
}
km.setStatus('textedit');
return;
}
}
if (mouseDownStatus) { if (mouseDownStatus) {
if (!sel.collapsed) { if (!sel.collapsed) {
...@@ -177,12 +222,16 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -177,12 +222,16 @@ KityMinder.registerModule('TextEditModule', function() {
console.log(error); console.log(error);
} }
} else { } else {
sel.setShow(); receiver.updateSelection();
} }
if (browser.ipad) { if (browser.ipad) {
receiver.container.focus(); receiver.container.focus();
} }
hasCursor = true;
km.setStatus('textedit');
} else { } else {
//当选中节点后,输入状态准备 //当选中节点后,输入状态准备
var node = e.getTargetNode(); var node = e.getTargetNode();
...@@ -208,9 +257,11 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -208,9 +257,11 @@ KityMinder.registerModule('TextEditModule', function() {
.updateRange(range).setTextEditStatus(true); .updateRange(range).setTextEditStatus(true);
sel.setData('relatedNode', node); sel.setData('relatedNode', node);
km.setStatus('textedit');
} }
} }
} }
...@@ -219,7 +270,7 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -219,7 +270,7 @@ KityMinder.registerModule('TextEditModule', function() {
}, },
'textedit.beforemousemove': function(e) { 'textedit.beforemousemove': function(e) {
//ipad下不做框选 //ipad下不做框选
if (mouseDownStatus && !browser.ipad) { if (mouseDownStatus && (sel.isShow() || hasCursor) && !browser.ipad) {
e.stopPropagationImmediately(); e.stopPropagationImmediately();
var offset = e.getPosition(this.getRenderContainer()); var offset = e.getPosition(this.getRenderContainer());
...@@ -240,7 +291,6 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -240,7 +291,6 @@ KityMinder.registerModule('TextEditModule', function() {
var text = e.kityEvent.targetShape; var text = e.kityEvent.targetShape;
if (text.getType().toLowerCase() == 'text') { if (text.getType().toLowerCase() == 'text') {
sel.setStartOffset(0); sel.setStartOffset(0);
sel.setEndOffset(text.getContent().length); sel.setEndOffset(text.getContent().length);
sel.setShow(); sel.setShow();
...@@ -336,7 +386,7 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -336,7 +386,7 @@ KityMinder.registerModule('TextEditModule', function() {
} }
}, },
'layoutfinish':function(e) { 'layoutfinish':function(e) {
if (e.node === receiver.minderNode && this.getStatus() == 'textedit') { if (e.node === receiver.minderNode && this.getStatus() == 'textedit' && hasCursor) {
receiver receiver
.setBaseOffset() .setBaseOffset()
.setContainerStyle() .setContainerStyle()
...@@ -364,6 +414,9 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -364,6 +414,9 @@ KityMinder.registerModule('TextEditModule', function() {
}, },
'textedit.mousewheel': function() { 'textedit.mousewheel': function() {
receiver.setContainerStyle(); receiver.setContainerStyle();
},
'treedragend':function(){
isSelected = false;
} }
} }
}; };
......
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