Commit 02f04f4c authored by campaign's avatar campaign

模拟光标这个整体调整

parent 82e40daf
...@@ -69,7 +69,7 @@ kity.extendClass(Minder, { ...@@ -69,7 +69,7 @@ kity.extendClass(Minder, {
KityMinder.registerModule('Connect', { KityMinder.registerModule('Connect', {
events: { events: {
'nodecreate': function(e) { 'nodeattach': function(e) {
this.createConnect(e.node); this.createConnect(e.node);
}, },
'noderemove': function(e) { 'noderemove': function(e) {
......
...@@ -88,9 +88,6 @@ var Minder = KityMinder.Minder = kity.createClass('KityMinder', { ...@@ -88,9 +88,6 @@ var Minder = KityMinder.Minder = kity.createClass('KityMinder', {
this._shortcutkeys = {}; this._shortcutkeys = {};
this._bindshortcutKeys(); this._bindshortcutKeys();
}, },
isTextEditStatus: function() {
return false;
},
addShortcutKeys: function(cmd, keys) { addShortcutKeys: function(cmd, keys) {
var obj = {}, var obj = {},
km = this; km = this;
......
...@@ -11,13 +11,20 @@ kity.extendClass(Minder, { ...@@ -11,13 +11,20 @@ kity.extendClass(Minder, {
createNode: function(unknown, parent, index) { createNode: function(unknown, parent, index) {
var node = new MinderNode(unknown); var node = new MinderNode(unknown);
this.fire('nodecreate', {
node: node
});
this.appendNode(node,parent, index);
return node;
},
appendNode: function(node, parent, index) {
if (parent) parent.insertChild(node, index); if (parent) parent.insertChild(node, index);
this.handelNodeCreate(node); this.handelNodeCreate(node);
this.fire('nodecreate', { this.fire('nodeattach', {
node: node node: node
}); });
return node; return this;
}, },
removeNode: function(node) { removeNode: function(node) {
......
...@@ -327,16 +327,16 @@ KityMinder.registerModule('DragTree', function() { ...@@ -327,16 +327,16 @@ KityMinder.registerModule('DragTree', function() {
dragger = new TreeDragger(this); dragger = new TreeDragger(this);
}, },
events: { events: {
'mousedown': function(e) { 'normal.mousedown inputready.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()));
} }
}, },
'mousemove': function(e) { 'normal.mousemove': function(e) {
dragger.dragMove(e.getPosition(this.getRenderContainer())); dragger.dragMove(e.getPosition(this.getRenderContainer()));
}, },
'mouseup': function(e) { 'normal.mouseup': function(e) {
dragger.dragEnd(e.getPosition(this.getRenderContainer())); dragger.dragEnd(e.getPosition(this.getRenderContainer()));
e.stopPropagation(); e.stopPropagation();
this.fire('contentchange'); this.fire('contentchange');
......
This diff is collapsed.
...@@ -12,17 +12,10 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -12,17 +12,10 @@ Minder.Receiver = kity.createClass('Receiver', {
this.isTypeText = false; this.isTypeText = false;
return this; return this;
}, },
setTextEditStatus: function(status) { constructor: function(km,sel,range) {
this.textEditStatus = status || false;
return this;
},
isTextEditStatus: function() {
return this.textEditStatus;
},
constructor: function(km) {
var me = this; var me = this;
this.setKityMinder(km); this.setKityMinder(km);
this.textEditStatus = false;
var _div = document.createElement('div'); var _div = document.createElement('div');
_div.setAttribute('contenteditable', true); _div.setAttribute('contenteditable', true);
_div.className = 'km_receiver'; _div.className = 'km_receiver';
...@@ -33,9 +26,11 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -33,9 +26,11 @@ 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.beforekeydown textedit.keypress textedit.paste', utils.proxy(this.keyboardEvents, this)); this.km.on('inputready.beforekeyup inputready.beforekeydown 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;
this.selection = sel;
this.range = range;
}, },
setRange: function(range, index) { setRange: function(range, index) {
...@@ -76,15 +71,30 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -76,15 +71,30 @@ Minder.Receiver = kity.createClass('Receiver', {
}, },
setMinderNode: function(node) { setMinderNode: function(node) {
this.minderNode = node; this.minderNode = node;
//更新minderNode下的textshape
this.setTextShape(node.getTextShape());
//更新textshape的baseOffset
this.setBaseOffset();
//更新接受容器的样式
this.setContainerStyle();
//更新textOffsetData数据
this.updateTextOffsetData();
//更新选取高度
this.setSelectionHeight();
//更新接收容器内容
this.setContainerTxt();
return this; return this;
}, },
getMinderNode:function(){
return this.minderNode;
},
keyboardEvents: function(e) { keyboardEvents: function(e) {
clearTimeout(this.timer); clearTimeout(this.timer);
var me = this; var me = this;
var orgEvt = e.originEvent; var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode; var keyCode = orgEvt.keyCode;
var keys = KityMinder.keymap;
function setTextToContainer() { function setTextToContainer() {
if (!me.range.hasNativeRange()) { if (!me.range.hasNativeRange()) {
...@@ -109,7 +119,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -109,7 +119,7 @@ Minder.Receiver = kity.createClass('Receiver', {
me.minderNode.render(); me.minderNode.render();
clearTimeout(me.inputTextTimer); clearTimeout(me.inputTextTimer);
me.inputTextTimer = setTimeout(function(){ me.inputTextTimer = setTimeout(function(){
me.km.layout(300); me.km.layout();
},250); },250);
me.textShape = me.minderNode.getRenderer('TextRenderer').getRenderShape(); me.textShape = me.minderNode.getRenderer('TextRenderer').getRenderShape();
...@@ -117,15 +127,14 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -117,15 +127,14 @@ Minder.Receiver = kity.createClass('Receiver', {
me.textShape.setOpacity(0); me.textShape.setOpacity(0);
} }
me.setBaseOffset(); me.setBaseOffset();
me.updateTextData(); me.updateTextOffsetData();
me.updateIndex(); me.updateIndex();
me.updateSelection(); me.updateSelection();
me.timer = setTimeout(function() { me.timer = setTimeout(function() {
me.selection.setShow(); me.selection.setShow();
}, 300); }, 300);
me.km.setStatus('textedit');
} }
...@@ -144,8 +153,14 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -144,8 +153,14 @@ Minder.Receiver = kity.createClass('Receiver', {
switch (keyCode) { switch (keyCode) {
case keymap.Enter: case keymap.Enter:
case keymap.Tab: case keymap.Tab:
case keymap.left:
case keymap.right:
case keymap.up:
case keymap.down:
if(this.selection.isShow()){ if(this.selection.isShow()){
this.clear().setTextEditStatus(false); this.clear();
this.km.setStatus('inputready');
clearTimeout(me.inputTextTimer);
e.preventDefault(); e.preventDefault();
}else{ }else{
this.km.setStatus('normal'); this.km.setStatus('normal');
...@@ -157,6 +172,12 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -157,6 +172,12 @@ Minder.Receiver = kity.createClass('Receiver', {
case keymap.Alt: case keymap.Alt:
case keymap.Cmd: case keymap.Cmd:
return; return;
case keymap.Del:
case keymap.Backspace:
if(!this.selection.isShow()){
this.km.setStatus('normal');
return;
}
} }
if (e.originEvent.ctrlKey || e.originEvent.metaKey) { if (e.originEvent.ctrlKey || e.originEvent.metaKey) {
...@@ -197,7 +218,6 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -197,7 +218,6 @@ Minder.Receiver = kity.createClass('Receiver', {
} }
if (this.keydownNode === this.minderNode) { if (this.keydownNode === this.minderNode) {
this.rollbackStatus(); this.rollbackStatus();
this.setTextEditStatus(false);
this.clear(); this.clear();
} }
e.preventDefault(); e.preventDefault();
...@@ -205,6 +225,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -205,6 +225,7 @@ Minder.Receiver = kity.createClass('Receiver', {
case keymap.Del: case keymap.Del:
case keymap.Backspace: case keymap.Backspace:
case keymap.Spacebar: case keymap.Spacebar:
setTextToContainer(); setTextToContainer();
return; return;
} }
...@@ -222,7 +243,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -222,7 +243,7 @@ Minder.Receiver = kity.createClass('Receiver', {
this.index = this.range.getStart().startOffset; this.index = this.range.getStart().startOffset;
return this; return this;
}, },
updateTextData: function() { updateTextOffsetData: function() {
this.textShape.textData = this.getTextOffsetData(); this.textShape.textData = this.getTextOffsetData();
return this; return this;
}, },
...@@ -406,18 +427,31 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -406,18 +427,31 @@ Minder.Receiver = kity.createClass('Receiver', {
return this; return this;
}, },
updateRange: function(range) { updateRange: function(range) {
range = range || this.range;
var node = this.container.firstChild; var node = this.container.firstChild;
range.setStart(node, this.selection.startOffset); range.setStart(node, this.selection.startOffset);
range.setEnd(node, this.selection.endOffset); range.setEnd(node, this.selection.endOffset);
range.select(); range.select();
return this; return this;
}, },
updateContainerRangeBySel:function(){
this.updateRange(this.range)
},
setIndex: function(index) { setIndex: function(index) {
this.index = index; this.index = index;
return this; return this;
}, },
setContainerTxt: function(txt) { setContainerTxt: function(txt) {
this.container.textContent = txt; this.container.textContent = txt || this.textShape.getContent();
return this; return this;
},
setReady:function(){
this._ready = true;
},
clearReady:function(){
this._ready = false;
},
isReady:function(){
return this._ready;
} }
}); });
\ No newline at end of file
...@@ -82,10 +82,12 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -82,10 +82,12 @@ Minder.Selection = kity.createClass( 'Selection', {
} catch ( e ) { } catch ( e ) {
console.log(e); console.log(e);
} }
return this.update(); this.update();
return this;
}, },
setHeight: function ( height ) { setHeight: function ( height ) {
this.height = height; this.height = height;
return this;
}, },
setHide: function () { setHide: function () {
clearInterval( this.timer ); clearInterval( this.timer );
...@@ -112,12 +114,14 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -112,12 +114,14 @@ Minder.Selection = kity.createClass( 'Selection', {
state = state ? '' : 'none'; state = state ? '' : 'none';
}, 400 ); }, 400 );
} }
return this; return this;
}, },
isShow:function(){ isShow:function(){
return this._show; return this._show;
}, },
isHide:function(){
return !this._show;
},
setTextShape: function ( text ) { setTextShape: function ( text ) {
if ( !text ) { if ( !text ) {
this.text = new kity.Text(); this.text = new kity.Text();
......
...@@ -68,7 +68,9 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -68,7 +68,9 @@ KityMinder.registerModule("HistoryModule", function() {
} }
function appendChildNode(parent, child) { function appendChildNode(parent, child) {
parent.appendChild(child);
km.appendNode(child,parent);
child.render();
for (var i = 0, ci; ci = child.children[i++];) { for (var i = 0, ci; ci = child.children[i++];) {
appendChildNode(child, ci); appendChildNode(child, ci);
} }
...@@ -101,6 +103,7 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -101,6 +103,7 @@ KityMinder.registerModule("HistoryModule", function() {
traverseNode(km.getRoot(), target); traverseNode(km.getRoot(), target);
km.layout(); km.layout();
}, },
restore: function() { restore: function() {
var scene = this.list[this.index]; var scene = this.list[this.index];
......
...@@ -30,7 +30,7 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', { ...@@ -30,7 +30,7 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
km.select(node, true); km.select(node, true);
node.render(); node.render();
node._lastLayoutTransform = sibling._lastLayoutTransform; node._lastLayoutTransform = sibling._lastLayoutTransform;
km.layout(3000); km.layout(300);
}, },
queryState: function(km) { queryState: function(km) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
......
...@@ -29,7 +29,7 @@ KityMinder.registerModule('Select', function() { ...@@ -29,7 +29,7 @@ KityMinder.registerModule('Select', function() {
startPosition = g.snapToSharp(e.getPosition()); startPosition = g.snapToSharp(e.getPosition());
}, },
selectMove: function(e) { selectMove: function(e) {
if (minder.isTextEditStatus()) { if (minder.getStatus() == 'textedit') {
return; return;
} }
if (!startPosition) return; if (!startPosition) return;
...@@ -95,7 +95,8 @@ KityMinder.registerModule('Select', function() { ...@@ -95,7 +95,8 @@ KityMinder.registerModule('Select', function() {
var lastDownNode = null, lastDownPosition = null; var lastDownNode = null, lastDownPosition = null;
return { return {
'events': { 'events': {
'normal.mousedown textedit.mousedown': function(e) { 'normal.mousedown textedit.mousedown inputready.mousedown': function(e) {
var downNode = e.getTargetNode(); var downNode = e.getTargetNode();
// 没有点中节点: // 没有点中节点:
...@@ -127,8 +128,8 @@ KityMinder.registerModule('Select', function() { ...@@ -127,8 +128,8 @@ KityMinder.registerModule('Select', function() {
lastDownPosition = e.getPosition(this.getRenderContainer()); lastDownPosition = e.getPosition(this.getRenderContainer());
} }
}, },
'normal.mousemove textedit.mousemove': marqueeActivator.selectMove, 'normal.mousemove textedit.mousemove inputready.mousemove': marqueeActivator.selectMove,
'normal.mouseup textedit.mouseup': function(e) { 'normal.mouseup textedit.mouseup inputready.mouseup': function(e) {
var upNode = e.getTargetNode(); var upNode = e.getTargetNode();
// 如果 mouseup 发生在 lastDownNode 外,是无需理会的 // 如果 mouseup 发生在 lastDownNode 外,是无需理会的
......
...@@ -30,6 +30,11 @@ utils.extend(TextRenderer, { ...@@ -30,6 +30,11 @@ utils.extend(TextRenderer, {
} }
}); });
kity.extendClass(MinderNode,{
getTextShape : function(){
return this.getRenderer('TextRenderer').getRenderShape();
}
});
KityMinder.registerModule('text', { KityMinder.registerModule('text', {
'renderers': { 'renderers': {
center: TextRenderer center: TextRenderer
......
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