Commit fb4cc971 authored by campaign's avatar campaign

添加方向键

parent 8d5c3ca6
...@@ -63,6 +63,9 @@ kity.extendClass( Minder, function () { ...@@ -63,6 +63,9 @@ kity.extendClass( Minder, function () {
highlightNode( me, n ) highlightNode( me, n )
} ); } );
this._selectedNodes = nodes; this._selectedNodes = nodes;
},
isSingleSelect:function(){
return this.getSelectedNodes().length == 1
} }
} }
}() ); }() );
\ No newline at end of file
...@@ -46,61 +46,13 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -46,61 +46,13 @@ KityMinder.registerModule( "KeyboardModule", function () {
}; };
} }
function findMinDepthNode( nodes ) {
var depth,
minDepth = Number.MAX_VALUE,
minDepthNode = null;
for ( var i = 0; i < nodes.length; i++ ) {
depth = nodes[ i ].getDepth();
if ( depth < minDepth ) {
minDepth = depth;
minDepthNode = nodes[ i ];
}
}
return minDepthNode;
}
var KBNavigateCommand = kity.createClass( { function KBNavigate(km,direction){
base: Command, var nextNode = km.getSelectedNode()._nearestNodes[ direction ];
execute: function ( km, direction, referNode ) { if ( nextNode ) {
var nextNode = referNode._nearestNodes[ direction ]; km.select(nextNode);
if ( nextNode ) {
km.toggleSelect( [ referNode, nextNode ] );
km.execCommand( 'rendernode', [ referNode, nextNode ] );
}
this.setContentChanged( false );
}
} );
var KBRemoveCommand = kity.createClass( {
base: Command,
execute: function ( km, nodes ) {
if ( !nodes.length ) {
return;
}
km.clearSelect( nodes );
var select = this.getNextSelection( km, nodes );
km.execCommand( 'removeNode', nodes );
km.select( select );
km.execCommand( 'rendernode', select );
},
getNextSelection: function ( km, removeNodes ) {
var minDepthNode = findMinDepthNode( removeNodes );
var parent = minDepthNode.getParent();
if ( !parent ) {
return km.getRoot();
}
var length = parent.getChildren().length;
if ( length > 1 ) {
var index = minDepthNode.getIndex() + 1;
return parent.getChild( index % length );
} else {
return parent;
}
} }
} ); }
return { return {
"events": { "events": {
...@@ -111,40 +63,33 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -111,40 +63,33 @@ KityMinder.registerModule( "KeyboardModule", function () {
switch ( e.originEvent.keyCode ) { switch ( e.originEvent.keyCode ) {
case 13: case 13:
// Enter // Enter
this.execCommand('appendSiblingNode',new MinderNode('Topic')); this.execCommand('appendSiblingNode',new MinderNode('Topic'));
break; break;
case 9: case 9:
// Tab // Tab
this.execCommand('appendChildNode',new MinderNode('Topic')); this.execCommand('appendChildNode',new MinderNode('Topic'));
break; break;
case 8:
case 8: case 46:
case 46: this.execCommand('removenode');
// Backspace or Delete break;
var rootIndex = sNodes.indexOf( this.getRoot() ); case 37:
if ( rootIndex != -1 ) { case 38:
sNodes.splice( rootIndex, 1 ); case 39:
} case 40:
this.execCommand( 'kbRemove', sNodes ); if ( this.isSingleSelect() ) {
break; KBNavigate(this,{
37: 'left',
case 37: 38: 'top',
case 38: 39: 'right',
case 39: 40: 'down'
case 40: }[ e.originEvent.keyCode ]);
if ( isSingleSelected ) { }
this.execCommand( 'kbNavigate', { break;
37: 'left',
38: 'top',
39: 'right',
40: 'down'
}[ e.originEvent.keyCode ], sNodes[ 0 ] );
} }
break;
} }
}
} }
}; };
} ); } );
\ No newline at end of file
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