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 ) {
var nextNode = referNode._nearestNodes[ direction ];
if ( nextNode ) { if ( nextNode ) {
km.toggleSelect( [ referNode, nextNode ] ); km.select(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": {
...@@ -119,28 +71,21 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -119,28 +71,21 @@ KityMinder.registerModule( "KeyboardModule", function () {
// Tab // Tab
this.execCommand('appendChildNode',new MinderNode('Topic')); this.execCommand('appendChildNode',new MinderNode('Topic'));
break; break;
case 8: case 8:
case 46: case 46:
// Backspace or Delete this.execCommand('removenode');
var rootIndex = sNodes.indexOf( this.getRoot() );
if ( rootIndex != -1 ) {
sNodes.splice( rootIndex, 1 );
}
this.execCommand( 'kbRemove', sNodes );
break; break;
case 37: case 37:
case 38: case 38:
case 39: case 39:
case 40: case 40:
if ( isSingleSelected ) { if ( this.isSingleSelect() ) {
this.execCommand( 'kbNavigate', { KBNavigate(this,{
37: 'left', 37: 'left',
38: 'top', 38: 'top',
39: 'right', 39: 'right',
40: 'down' 40: 'down'
}[ e.originEvent.keyCode ], sNodes[ 0 ] ); }[ e.originEvent.keyCode ]);
} }
break; break;
} }
......
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