Commit 09a3fa39 authored by campaign's avatar campaign

改进节点删除为空时的处理机制

parent 1d1e499c
...@@ -20,6 +20,7 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -20,6 +20,7 @@ KityMinder.registerModule('TextEditModule', function() {
function inputStatusReady(node){ function inputStatusReady(node){
if (node && km.isSingleSelect() && node.isSelected()) { if (node && km.isSingleSelect() && node.isSelected()) {
var color = node.getStyle('text-selection-color'); var color = node.getStyle('text-selection-color');
//准备输入状态 //准备输入状态
...@@ -47,8 +48,6 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -47,8 +48,6 @@ KityMinder.registerModule('TextEditModule', function() {
} }
receiver.minderNode.setTmpData('_lastTextContent',receiver.textShape.getContent());
km.setStatus('inputready'); km.setStatus('inputready');
} }
...@@ -73,16 +72,6 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -73,16 +72,6 @@ KityMinder.registerModule('TextEditModule', function() {
} }
if(receiver.minderNode){
var textShape = receiver.minderNode.getTextShape();
if(textShape && textShape.getOpacity() === 0){
receiver.minderNode.setText(receiver.minderNode.getTmpData('_lastTextContent'));
receiver.minderNode.render();
receiver.minderNode.getTextShape().setOpacity(1);
km.layout(300);
}
}
mouseDownStatus = true; mouseDownStatus = true;
selectionReadyShow = sel.isShow(); selectionReadyShow = sel.isShow();
...@@ -104,6 +93,7 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -104,6 +93,7 @@ KityMinder.registerModule('TextEditModule', function() {
if(node){ if(node){
var textShape = node.getTextShape(); var textShape = node.getTextShape();
textShape.setStyle('cursor', 'default'); textShape.setStyle('cursor', 'default');
if (this.isSingleSelect() && node.isSelected()) { if (this.isSingleSelect() && node.isSelected()) {
sel.collapse(true); sel.collapse(true);
......
...@@ -75,7 +75,9 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -75,7 +75,9 @@ Minder.Receiver = kity.createClass('Receiver', {
return this; return this;
}, },
getTextShapeHeight: function() { getTextShapeHeight: function() {
return this.textShape.getRenderBox().height; var height = this.textShape.getRenderBox().height;
return height || this.minderNode._lastTextShapeBox.height;
}, },
setKityMinder: function(km) { setKityMinder: function(km) {
this.km = km; this.km = km;
...@@ -115,7 +117,6 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -115,7 +117,6 @@ Minder.Receiver = kity.createClass('Receiver', {
var keyCode = orgEvt.keyCode; var keyCode = orgEvt.keyCode;
function setTextToContainer() { function setTextToContainer() {
clearTimeout(me.timer); clearTimeout(me.timer);
if (!me.range.hasNativeRange()) { if (!me.range.hasNativeRange()) {
return; return;
...@@ -139,26 +140,11 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -139,26 +140,11 @@ Minder.Receiver = kity.createClass('Receiver', {
text += '\u200b'; text += '\u200b';
} }
me.minderNode.setText(text);
//如果接受框已经空了,并且已经添加了占位的a了就什么都不做了
if(text.length === 0 && me.textShape.getOpacity() === 0){
return;
}
if (text.length === 0) {
me.minderNode.setTmpData('_lastTextContent',me.textShape.getContent());
me.minderNode.setText('a');
}else {
me.minderNode.setText(text);
if (me.textShape.getOpacity() === 0) {
me.textShape.setOpacity(1);
}
}
me.setContainerStyle(); me.setContainerStyle();
me.minderNode.getRenderContainer().bringTop(); me.minderNode.getRenderContainer().bringTop();
me.minderNode.render(); me.minderNode.render();
//移动光标不做layout //移动光标不做layout
if(!keymap.notContentChange[keyCode]){ if(!keymap.notContentChange[keyCode]){
clearTimeout(me.inputTextTimer); clearTimeout(me.inputTextTimer);
...@@ -170,9 +156,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -170,9 +156,7 @@ Minder.Receiver = kity.createClass('Receiver', {
me.textShape = me.minderNode.getRenderer('TextRenderer').getRenderShape(); me.textShape = me.minderNode.getRenderer('TextRenderer').getRenderShape();
if (text.length === 0) {
me.textShape.setOpacity(0);
}
me.setBaseOffset(); me.setBaseOffset();
me.updateTextOffsetData(); me.updateTextOffsetData();
me.updateRange(); me.updateRange();
...@@ -187,18 +171,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -187,18 +171,7 @@ Minder.Receiver = kity.createClass('Receiver', {
me.km.setStatus('textedit'); me.km.setStatus('textedit');
} }
function restoreTextContent(){
if(me.minderNode){
var textShape = me.minderNode.getTextShape();
if(textShape && textShape.getOpacity() === 0){
me.minderNode.setText(me.minderNode.getTmpData('_lastTextContent'));
me.minderNode.render();
me.minderNode.getTextShape().setOpacity(1);
me.km.layout(300);
}
}
}
switch (e.type) { switch (e.type) {
case 'input': case 'input':
...@@ -223,7 +196,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -223,7 +196,7 @@ Minder.Receiver = kity.createClass('Receiver', {
this.km.setStatus('normal'); this.km.setStatus('normal');
this.km.fire('contentchange'); this.km.fire('contentchange');
} }
restoreTextContent();
return; return;
case keymap.left: case keymap.left:
case keymap.right: case keymap.right:
...@@ -233,7 +206,6 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -233,7 +206,6 @@ Minder.Receiver = kity.createClass('Receiver', {
case keymap.Del: case keymap.Del:
case keymap['/']: case keymap['/']:
if(this.selection.isHide()){ if(this.selection.isHide()){
restoreTextContent();
this.km.setStatus('normal'); this.km.setStatus('normal');
return; return;
} }
...@@ -257,7 +229,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -257,7 +229,7 @@ Minder.Receiver = kity.createClass('Receiver', {
88:1, 88:1,
67:1 67:1
}[keyCode]){ }[keyCode]){
restoreTextContent();
this.km.setStatus('normal'); this.km.setStatus('normal');
return; return;
} }
...@@ -305,7 +277,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -305,7 +277,7 @@ Minder.Receiver = kity.createClass('Receiver', {
this.km.setStatus('normal'); this.km.setStatus('normal');
this.km.fire('contentchange'); this.km.fire('contentchange');
} }
restoreTextContent(); shide
return; return;
} }
if (keymap.Enter == keyCode && (this.isTypeText || browser.mac && browser.gecko)) { if (keymap.Enter == keyCode && (this.isTypeText || browser.mac && browser.gecko)) {
...@@ -343,6 +315,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -343,6 +315,7 @@ Minder.Receiver = kity.createClass('Receiver', {
return true; return true;
case 'keyup': case 'keyup':
var node = this.km.getSelectedNode(); var node = this.km.getSelectedNode();
if(this.km.getStatus() == 'normal' && node && this.selection.isHide()){ if(this.km.getStatus() == 'normal' && node && this.selection.isHide()){
if (node && this.km.isSingleSelect() && node.isSelected()) { if (node && this.km.isSingleSelect() && node.isSelected()) {
...@@ -374,8 +347,6 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -374,8 +347,6 @@ Minder.Receiver = kity.createClass('Receiver', {
} }
this.minderNode.setTmpData('_lastTextContent',this.textShape.getContent());
this.km.setStatus('inputready'); this.km.setStatus('inputready');
} }
...@@ -390,7 +361,7 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -390,7 +361,7 @@ Minder.Receiver = kity.createClass('Receiver', {
return this; return this;
}, },
updateTextOffsetData: function() { updateTextOffsetData: function() {
this.textShape.textData = this.getTextOffsetData(); this.getTextOffsetData();
return this; return this;
}, },
setSelection: function(selection) { setSelection: function(selection) {
...@@ -452,6 +423,15 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -452,6 +423,15 @@ Minder.Receiver = kity.createClass('Receiver', {
height: box.height height: box.height
}); });
} }
if(this.textData.length === 0){
var lastBox = this.minderNode._lastTextShapeBox;
this.textData.push({
x: lastBox.x ,
y: lastBox.y,
width: 0,
height: lastBox.height
});
}
return this; return this;
}, },
setCurrentIndex: function(offset) { setCurrentIndex: function(offset) {
...@@ -460,6 +440,10 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -460,6 +440,10 @@ Minder.Receiver = kity.createClass('Receiver', {
var hadChanged = false; var hadChanged = false;
//要剪掉基数 //要剪掉基数
this._getRelativeValue(offset); this._getRelativeValue(offset);
if(this.textData.length == 1 && this.textData[0].width === 0){
me.index = 0;
return this;
}
utils.each(this.textData, function(i, v) { utils.each(this.textData, function(i, v) {
//点击开始之前 //点击开始之前
if (i === 0 && offset.x <= v.x) { if (i === 0 && offset.x <= v.x) {
...@@ -578,6 +562,9 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -578,6 +562,9 @@ Minder.Receiver = kity.createClass('Receiver', {
updateContainerRangeBySel:function(){ updateContainerRangeBySel:function(){
var me = this; var me = this;
var node = this.container.firstChild; var node = this.container.firstChild;
if(!node){
node = this.container;
}
this.range.setStart(node, this.selection.startOffset); this.range.setStart(node, this.selection.startOffset);
this.range.setEnd(node, this.selection.endOffset); this.range.setEnd(node, this.selection.endOffset);
if(browser.gecko){ if(browser.gecko){
......
...@@ -10,16 +10,35 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', { ...@@ -10,16 +10,35 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
.setAttr('text-rendering', 'inherit'); .setAttr('text-rendering', 'inherit');
}, },
update: function(text, node) { update: function(text,node) {
this.setTextStyle(node, text.setContent(node.getText()));
var box = text.getBoundaryBox(); var tmpText = node.getText();
var r = Math.round;
if (kity.Browser.ie) { this.setTextStyle(node, text.setContent(tmpText));
box.y += 1;
if(tmpText.length || !this._lastBox){
var box = text.getBoundaryBox();
var r = Math.round;
if (kity.Browser.ie) {
box.y += 1;
}
this._lastBox = {
x : r(box.x),
y : r(box.y),
width : r(box.width),
height: r(box.height)
};
}else {
this._lastBox.width = 0;
} }
var lastBox = this._lastBox;
node._lastTextShapeBox = lastBox;
return function() { return function() {
return new kity.Box(r(box.x), r(box.y), r(box.width), r(box.height)); return new kity.Box(lastBox.x, lastBox.y,lastBox.width, lastBox.height);
}; };
}, },
setTextStyle: function(node, text) { setTextStyle: function(node, text) {
......
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