Commit 564bb5a4 authored by campaign's avatar campaign

添加换行机制

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