Commit 564bb5a4 authored by campaign's avatar campaign

添加换行机制

parent 37352939
...@@ -281,7 +281,12 @@ var utils = Utils = KityMinder.Utils = { ...@@ -281,7 +281,12 @@ var utils = Utils = KityMinder.Utils = {
utils.each(data,function(i,arr){ utils.each(data,function(i,arr){
if(initIndex + arr.length >= index){ if(initIndex + arr.length >= index){
if(index - initIndex == arr.length){ if(index - initIndex == arr.length){
if(arr.length == 1 && arr[0].width === 0){
initIndex++;
return;
}
result = { result = {
x: arr[arr.length - 1].x + arr[arr.length - 1].width, x: arr[arr.length - 1].x + arr[arr.length - 1].width,
y: arr[arr.length - 1].y y: arr[arr.length - 1].y
......
...@@ -210,11 +210,14 @@ KityMinder.registerModule('TextEditModule', function() { ...@@ -210,11 +210,14 @@ KityMinder.registerModule('TextEditModule', function() {
var node = e.getTargetNode(); var node = e.getTargetNode();
e.stopPropagationImmediately(); e.stopPropagationImmediately();
var offset = e.getPosition(node.getRenderContainer()); if(node){
var offset = e.getPosition(node.getRenderContainer());
receiver.updateSelectionByMousePosition(offset) receiver.updateSelectionByMousePosition(offset)
.updateSelection(offset) .updateSelection(offset)
.updateContainerRangeBySel(); .updateContainerRangeBySel();
}
}else if(mouseDownStatus && !selectionReadyShow){ }else if(mouseDownStatus && !selectionReadyShow){
......
...@@ -309,6 +309,11 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){ ...@@ -309,6 +309,11 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){
}, },
//处理软回车操作 //处理软回车操作
_handlerEnterkey:function(){ _handlerEnterkey:function(){
function removeTmpTextNode(node){
if(node && node.nodeType == 3 && node.nodeValue.length === 0){
node.parentNode.removeChild(node);
}
}
var rng = this.range; var rng = this.range;
var br = document.createElement('br'); var br = document.createElement('br');
var me = this; var me = this;
...@@ -316,17 +321,17 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){ ...@@ -316,17 +321,17 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){
rng.deleteContents(); rng.deleteContents();
} }
rng.insertNode(br); rng.insertNode(br);
removeTmpTextNode(br.previousSibling);
removeTmpTextNode(br.nextSibling);
rng.setStartAfter(br); rng.setStartAfter(br);
rng.collapse(true); rng.collapse(true);
var start = rng.startContainer.childNodes[rng.startOffset]; var start = rng.startContainer.childNodes[rng.startOffset];
if(start && start.nodeType == 3 && start.nodeValue.length === 0){ if(!start){
start.parentNode.removeChild(start); br = br.cloneNode(false);
if(!rng.startContainer.childNodes[rng.startOffset]){ rng.startContainer.appendChild(br);
br = br.cloneNode(false); rng.setStartBefore(br);
rng.startContainer.appendChild(br); rng.collapse(true);
rng.setStartBefore(br);
rng.collapse(true);
}
} }
rng.select(); rng.select();
me._setTextToContainer(keymap.Enter); me._setTextToContainer(keymap.Enter);
......
...@@ -28,13 +28,13 @@ Minder.Range = kity.createClass('Range',function(){ ...@@ -28,13 +28,13 @@ Minder.Range = kity.createClass('Range',function(){
var rOffset = 0,cont = rng.container; var rOffset = 0,cont = rng.container;
utils.each(cont.childNodes,function(index,node){ utils.each(cont.childNodes,function(index,node){
if(node.nodeType == 1){ if(node.nodeType == 1){
rOffset++;
if(rOffset == offset){ if(rOffset == offset){
rng['set' + dir](cont,index); rng['set' + dir](cont,index);
return false; return false;
} }
rOffset++;
return; return;
} }
...@@ -65,6 +65,7 @@ Minder.Range = kity.createClass('Range',function(){ ...@@ -65,6 +65,7 @@ Minder.Range = kity.createClass('Range',function(){
return this._updateBoundary(); return this._updateBoundary();
}, },
select:function(){ select:function(){
var start = this.nativeRange.startContainer; var start = this.nativeRange.startContainer;
if(start.nodeType == 1 && start.childNodes.length === 0){ if(start.nodeType == 1 && start.childNodes.length === 0){
var char = document.createTextNode('\u200b'); var char = document.createTextNode('\u200b');
......
...@@ -194,8 +194,8 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -194,8 +194,8 @@ Minder.Receiver = kity.createClass('Receiver', {
return false; return false;
} }
if (i == arr.length - 1 && offset.x >= v.x) { if (i == arr.length - 1 && offset.x >= v.x) {
me.index += arr.length;
me.index += (arr.length == 1 && arr[0].width === 0 ? 0 : arr.length);
return false; return false;
} }
}); });
...@@ -245,7 +245,8 @@ Minder.Receiver = kity.createClass('Receiver', { ...@@ -245,7 +245,8 @@ Minder.Receiver = kity.createClass('Receiver', {
return false; return false;
} }
if (i == arr.length - 1 && offset.x >= v.x) { if (i == arr.length - 1 && offset.x >= v.x) {
result += arr.length;
result += (arr.length == 1 && arr[0].width === 0 ? 0 : arr.length);
return false; return 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