Commit 0cc1fa4b authored by campaign's avatar campaign

添加换行机制

parent 31c3b439
......@@ -296,10 +296,21 @@ var utils = Utils = KityMinder.Utils = {
}
});
return result;
},
getNodeIndex:function (node, ignoreTextNode) {
var preNode = node,
i = 0;
while (preNode = preNode.previousSibling) {
if (ignoreTextNode && preNode.nodeType == 3) {
if(preNode.nodeType != preNode.nextSibling.nodeType ){
i++;
}
continue;
}
i++;
}
return i;
}
};
......
......@@ -5,11 +5,15 @@ KityMinder.registerModule('basestylemodule', function() {
return node.getData(name) || node.getStyle(name);
}
KityMinder.TextRenderer.registerStyleHook(function(node, text) {
text.setFont({
weight: getNodeDataOrStyle(node, 'font-weight'),
style: getNodeDataOrStyle(node, 'font-style')
KityMinder.TextRenderer.registerStyleHook(function(node, textGroup) {
textGroup.eachItem(function(index,item){
item.setFont({
'weight': getNodeDataOrStyle(node,'font-weight'),
'style': getNodeDataOrStyle(node,'font-style')
});
});
});
return {
'commands': {
......
......@@ -53,7 +53,6 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){
}
},
_setTextToContainer : function(keyCode){
var me = this;
//同步节点
me.minderNode = me.re.minderNode;
......@@ -116,7 +115,6 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){
}
}, 200);
me.km.setStatus('textedit');
},
_input:function(e){
......@@ -137,7 +135,9 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){
switch (keyCode) {
case keymap.Enter:
if(e.originEvent.shiftKey){
return;
me._handlerEnterkey();
e.preventDefault();
return false;
}
case keymap.Tab:
if(this.selection.isShow()){
......@@ -222,11 +222,6 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){
switch (keyCode) {
case keymap.Enter:
if(e.originEvent.shiftKey){
me._setTextToContainer(keyCode);
return;
}
case keymap.Tab:
case keymap.F2:
if(browser.ipad){
......@@ -279,7 +274,6 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){
var me = this;
var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode;
var node = this.km.getSelectedNode();
if(this.km.getStatus() == 'normal' && node && this.selection.isHide()){
if (node && this.km.isSingleSelect() && node.isSelected()) {
......@@ -306,17 +300,23 @@ Minder.keyboarder = kity.createClass('keyboarder', function(){
});
}
this.km.setStatus('inputready');
}
}
},
_handlerEnterkey:function(e){
var textArr = [];
utils.each(this.container.childNodes,function(index,node){
textArr.push(node.nodeType == 1 ? '\n' : utils.clearWhitespace(node.nodeValue));
})
_handlerEnterkey:function(){
var rng = this.range;
var br = document.createElement('br');
var me = this;
if(!rng.collapsed){
rng.deleteContents();
}
rng.insertNode(br);
rng.setStartAfter(br);
rng.collapse(true);
rng.select();
me._setTextToContainer(keymap.Enter);
}
......
......@@ -7,6 +7,9 @@ Minder.Range = kity.createClass('Range',function(){
if(node.nodeType == 1){
//默认不会出现得不到子节点的情况
node = node.childNodes[offset];
if(node.nodeType == 3){
offset = 0;
}
}
utils.each(rng.container.childNodes,function(index,n){
if(n === node){
......@@ -57,6 +60,10 @@ Minder.Range = kity.createClass('Range',function(){
hasNativeRange : function(){
return this.nativeSel.rangeCount !== 0 ;
},
deleteContents : function(){
this.nativeRange.deleteContents();
return this._updateBoundary();
},
select:function(){
var start = this.nativeRange.startContainer;
if(start.nodeType == 1 && start.childNodes.length === 0){
......@@ -98,6 +105,9 @@ Minder.Range = kity.createClass('Range',function(){
this._updateBoundary();
return this;
},
setStartAfter:function(node){
return this.setStart(node.parentNode,utils.getNodeIndex(node) + 1);
},
setEnd:function(node,offset){
this.nativeRange.setEnd(node,offset);
this._updateBoundary();
......
......@@ -3,14 +3,18 @@ KityMinder.registerModule("fontmodule", function() {
return node.getData(name) || node.getStyle(name);
}
KityMinder.TextRenderer.registerStyleHook(function(node, text) {
KityMinder.TextRenderer.registerStyleHook(function(node, textGroup) {
var dataColor = node.getData('color');
var selectedColor = node.getStyle('selected-color');
var styleColor = node.getStyle('color');
text.fill(dataColor || (node.isSelected() && selectedColor ? selectedColor : styleColor));
text.setFont({
family: getNodeDataOrStyle(node, 'font-family'),
size: getNodeDataOrStyle(node, 'font-size')
textGroup.fill(dataColor || (node.isSelected() && selectedColor ? selectedColor : styleColor));
textGroup.eachItem(function(index,item){
item.setFont({
'family': getNodeDataOrStyle(node,'font-family'),
'size': getNodeDataOrStyle(node,'font-size')
});
});
});
......
......@@ -22,8 +22,8 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
r = Math.round;
this.setTextStyle(node, textGroup);
this.setTextStyle(node, textGroup);
for(var i= 0,text,textShape;
(text=textArr[i],textShape=textGroup.getItem(i),
......@@ -40,13 +40,19 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
}
textShape.setContent(text);
var y = i * fontSize * lineHeight - height;
textShape.setY(y);
rBox = rBox.merge(new kity.Box(0, y, textShape.getBoundaryBox().width, fontSize));
}
}
this.setTextStyle(node, textGroup);
textGroup.eachItem(function(i,textShape){
var y = i * fontSize * lineHeight - height;
textShape.setY(y);
rBox = rBox.merge(new kity.Box(0, y, textShape.getBoundaryBox().width, fontSize));
});
var nBox = new kity.Box(r(rBox.x), r(rBox.y),r(rBox.width), r(rBox.height));
......
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