Commit 02f04f4c authored by campaign's avatar campaign

模拟光标这个整体调整

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