Commit ead205d7 authored by campaign's avatar campaign

改进history的性能

parent f8800cc4
......@@ -299,8 +299,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return false;
}
} );
if(textShape === undefined)
debugger
return textShape;
},
isSelected: function () {
......@@ -318,7 +317,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
setTmpData: function ( a, v ) {
var me = this;
if ( utils.isObject( a ) ) {
utils.each( a, function ( val, key ) {
utils.each( a, function ( key,val) {
me.setTmpData( key, val )
} )
}
......@@ -333,5 +332,12 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return this.tmpData;
}
return this.tmpData[ a ]
},
setValue:function(node){
this.data = {};
this.setData(utils.clonePlainObject(node.getData()));
this.tmpData = {};
this.setTmpData(utils.clonePlainObject(node.getTmpData()));
return this;
}
} );
\ No newline at end of file
......@@ -106,11 +106,15 @@ KityMinder.registerModule( "TextEditModule", function () {
var node = this.getSelectedNode();
if(node){
if ( this.isSingleSelect() && node.isSelected()) {
var keyCode = e.originEvent.keyCode;
if(!keymap.notContentInput[keyCode] && range.nativeSel.rangeCount != 0){
var orgEvt = e.originEvent,keyCode = orgEvt.keyCode;
if(!keymap.notContentInput[keyCode] && range.nativeSel.rangeCount != 0 && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey){
var nativeRange = range.nativeSel.getRangeAt(0);
if(nativeRange && (nativeRange.startContainer === receiver.container || receiver.container.contains(nativeRange.startContainer )))
km.setStatus('textedit')
if(nativeRange && (nativeRange.startContainer === receiver.container || receiver.container.contains(nativeRange.startContainer ))){
km.setStatus('textedit');
km.fire('saveScene');
}
}
}
}
......@@ -120,8 +124,10 @@ KityMinder.registerModule( "TextEditModule", function () {
var node = this.getSelectedNode();
if(node){
if ( this.isSingleSelect() && node.isSelected()) {
var keyCode = e.originEvent.keyCode;
if(keymap.isSelectedNodeKey[keyCode] && km.getStatus() != 'textedit'){
var orgEvt = e.originEvent,keyCode = orgEvt.keyCode;
if(keymap.isSelectedNodeKey[keyCode] && km.getStatus() != 'textedit' && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey){
//准备输入状态
var textShape = node.getTextShape();
......@@ -225,7 +231,30 @@ KityMinder.registerModule( "TextEditModule", function () {
}
},
'restoreScene':function(){
sel.setHide();
var node = this.getSelectedNode();
if(node && this.isSingleSelect()){
var textShape = node.getTextShape();
sel.setHide();
sel.setStartOffset(0);
sel.setEndOffset(textShape.getContent().length);
receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
.setMinderNode(node)
.setTextShape(textShape)
.setRange(range)
.setBaseOffset()
.setContainerStyle()
.setSelectionHeight()
.setContainerTxt(textShape.getContent())
.updateRange(range).setTextEditStatus(true);
sel.setData('relatedNode',node);
}else {
receiver.clear()
}
},
'stopTextEdit':function(){
sel.setHide();
......
......@@ -95,7 +95,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
if ( browser.gecko && /\s$/.test( text ) ) {
text += "\u200b";
}
me.textShape.setContent( text );
me.setContainerStyle();
me.minderNode.setText( text );
if ( text.length == 0 ) {
......@@ -127,20 +127,16 @@ Minder.Receiver = kity.createClass( 'Receiver', {
isTypeText = false;
isKeypress = false;
switch ( e.originEvent.keyCode ) {
case keys.Enter:
case keys.Tab:
this.selection.setHide();
this.clear().setTextEditStatus( false );
this.km.fire( 'contentchange' );
this.km.setStatus( 'normal' );
e.preventDefault();
return;
break;
case keymap.Shift:
case keymap.Control:
case keymap.Alt:
case keymap.Cmd:
return;
case keys.Enter:
case keys.Tab:
this.selection.setHide();
this.clear().setTextEditStatus( false );
this.km.fire( 'contentchange' );
this.km.setStatus( 'normal' );
e.preventDefault();
return;
break;
}
if ( e.originEvent.ctrlKey || e.originEvent.metaKey ) {
......@@ -167,19 +163,21 @@ Minder.Receiver = kity.createClass( 'Receiver', {
}
isTypeText = true;
setTextToContainer();
if(!orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey){
setTextToContainer();
}
break;
case 'keypress':
if ( isTypeText )
// setTextToContainer();
isKeypress = true;
break;
case 'beforekeyup':
switch ( keyCode ) {
case keymap.Enter:
case keymap.Tab:
......@@ -195,7 +193,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
}
if ( !isKeypress ) {
if ( !isKeypress && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey ) {
setTextToContainer();
}
return true;
......
......@@ -26,6 +26,9 @@ KityMinder.registerModule( "HistoryModule", function () {
},
undo: function () {
if ( this.hasUndo ) {
// if(this.km.getStatus() == 'textedit'){
// return this.restore(this.index);
// }
if ( !this.list[ this.index - 1 ] && this.list.length == 1 ) {
this.reset();
return;
......@@ -36,7 +39,7 @@ KityMinder.registerModule( "HistoryModule", function () {
return this.restore( 0 );
}
}
this.restore( --this.index );
this.restore( --this.index);
}
},
redo: function () {
......@@ -44,19 +47,62 @@ KityMinder.registerModule( "HistoryModule", function () {
while ( this.list[ this.index ].equals( this.list[ this.index + 1 ] ) ) {
this.index++;
if ( this.index == this.list.length - 1 ) {
return this.restore( this.index );
return this.restore( this.index);
}
}
this.restore( ++this.index );
this.restore( ++this.index);
}
},
restore: function () {
var scene = this.list[ this.index ];
partialRenewal:function(target){
function compareNode(source,target){
if(source.getText()!=target.getText()){
return false;
}
if ( utils.compareObject( source.getData(), target.getData() ) === false ) {
return false;
}
if ( utils.compareObject( source.getTmpData(), target.getTmpData() ) === false ) {
return false;
}
return true;
}
this.km.setRoot( scene.cloneData() );
this.km.removeAllSelectedNodes();
this.km.initStyle();
function appendChildNode(parent,child){
km.appendChildNode(parent,child);
for(var i= 0,ci;ci=child.children[i++];){
appendChildNode(child,ci)
}
}
function traverseNode(srcNode,tagNode){
if(compareNode(srcNode,tagNode) === false){
km.updateLayout(srcNode.setValue(tagNode));
if(srcNode.isSelected()){
km.select(srcNode)
}else{
km.removeSelectedNodes(srcNode)
}
}
for ( var i = 0, j = 0,si,tj;
( si = srcNode.children[ i ] , tj = tagNode.children[j], si || tj); i++,j++ ) {
if(si && !tj){
i--;
km.removeNode(si)
}else if(!si && tj){
j--;
appendChildNode(srcNode,tj)
}else {
traverseNode(si,tj)
}
}
}
traverseNode(km.getRoot(),target)
},
restore: function () {
var scene = this.list[ this.index ];
this.partialRenewal(scene.cloneData());
this.update();
this.km.fire( 'restoreScene' );
this.km.fire( 'contentChange' );
......@@ -82,7 +128,7 @@ KityMinder.registerModule( "HistoryModule", function () {
},
update: function () {
this.hasRedo = !! this.list[ this.index + 1 ];
this.hasUndo = !! this.list[ this.index - 1 ];
this.hasUndo = !! this.list[ this.index - 1 ] //|| this.km.getStatus() == 'textedit';
},
reset: function () {
this.list = [];
......@@ -161,28 +207,28 @@ KityMinder.registerModule( "HistoryModule", function () {
this.select( node )
}
},
"keydown": function ( e ) {
var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode || orgEvt.which;
if ( !keys[ keyCode ] && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey ) {
if ( km.historyManager.list.length == 0 ) {
km.historyManager.saveScene();
}
clearTimeout( saveSceneTimer );
saveSceneTimer = setTimeout( function () {
km.historyManager.saveScene();
}, 200 );
lastKeyCode = keyCode;
keycont++;
if ( keycont >= km.getOptions( 'maxInputCount' ) ) {
km.historyManager.saveScene()
}
}
},
// "keydown": function ( e ) {
// var orgEvt = e.originEvent;
// var keyCode = orgEvt.keyCode || orgEvt.which;
// if ( !keys[ keyCode ] && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey ) {
//
//
// if ( km.historyManager.list.length == 0 ) {
// km.historyManager.saveScene();
// }
// clearTimeout( saveSceneTimer );
//
// saveSceneTimer = setTimeout( function () {
// km.historyManager.saveScene();
// }, 200 );
//
// lastKeyCode = keyCode;
// keycont++;
// if ( keycont >= km.getOptions( 'maxInputCount' ) ) {
// km.historyManager.saveScene()
// }
// }
// },
"import": function () {
this.historyManager.reset()
}
......
......@@ -712,6 +712,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
this.appendChildNode( parent, node, focus, sibling );
},
removeNode: function ( nodes ) {
nodes = utils.isArray(nodes) ? nodes : [nodes];
while ( nodes.length !== 0 ) {
var parent = nodes[ 0 ].getParent();
if ( !parent ) {
......
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