Commit 60777228 authored by campaign's avatar campaign

enterkey/tabkey

parent b7b47ab0
...@@ -11,7 +11,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -11,7 +11,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
this.rc = new kity.Group(); this.rc = new kity.Group();
this.rc.minderNode = this; this.rc.minderNode = this;
}, },
isRoot:function(){
return this.getParent() == null ? true : false;
},
getParent: function () { getParent: function () {
return this.parent; return this.parent;
}, },
......
...@@ -60,19 +60,6 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -60,19 +60,6 @@ KityMinder.registerModule( "KeyboardModule", function () {
return minDepthNode; return minDepthNode;
} }
var KBCreateAndEditCommand = kity.createClass( {
base: Command,
execute: function ( km, type, referNode ) {
var node = this.createdNode = km.execCommand( 'create' + type + 'node', referNode );
km.selectSingle( node );
km.execCommand( 'editText', node );
this.setContentChanged( true );
},
revert: function ( km ) {
km.execCommand( 'removeNode', this.createdNode );
}
} );
var KBNavigateCommand = kity.createClass( { var KBNavigateCommand = kity.createClass( {
base: Command, base: Command,
...@@ -115,40 +102,22 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -115,40 +102,22 @@ KityMinder.registerModule( "KeyboardModule", function () {
} ); } );
return { return {
// private usage
"commands": {
'kbCreateAndEdit': KBCreateAndEditCommand,
'kbNavigate': KBNavigateCommand,
'kbRemove': KBRemoveCommand
},
"events": { "events": {
contentchange: function () { contentchange: function () {
buildPositionNetwork( this.getRoot() ); buildPositionNetwork( this.getRoot() );
}, },
keydown: function ( e ) { keydown: function ( e ) {
var sNodes = this.getSelectedNodes(),
isSingleSelected = sNodes.length === 1,
isRootSelected = this.isNodeSelected( this.getRoot() );
switch ( e.originEvent.keyCode ) { switch ( e.originEvent.keyCode ) {
case 13: case 13:
// Enter // Enter
if ( isSingleSelected ) { this.execCommand('appendSiblingNode',new MinderNode('Topic'));
if ( isRootSelected ) {
this.execCommand( 'kbCreateAndEdit', 'child', sNodes[ 0 ] );
} else {
this.execCommand( 'kbCreateAndEdit', 'sibling', sNodes[ 0 ] );
}
}
break; break;
case 9: case 9:
// Tab // Tab
if ( isSingleSelected ) { this.execCommand('appendChildNode',new MinderNode('Topic'));
this.execCommand( 'kbCreateAndEdit', 'child', sNodes[ 0 ] );
}
break; break;
case 8: case 8:
......
...@@ -39,8 +39,12 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -39,8 +39,12 @@ KityMinder.registerModule( "LayoutModule", function () {
base: Command, base: Command,
execute: function ( km, node ) { execute: function ( km, node ) {
//km.select( node ); //km.select( node );
var sibling = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
km.appendSiblingNode( sibling, node ); if(selectedNode.isRoot()){
km.appendChildNode( selectedNode, node );
}else{
km.appendSiblingNode( selectedNode, node );
}
km.select( node ); km.select( node );
return node; return node;
} }
......
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