Let Tab and Shift+Tab trigger indentation again

Fix the commented-out code: it caused unindent to be triggered by just
pressing Shift. ASCII 16 is "data link escape", no idea where that came
from, so I removed it and used e.shiftKey instead.

Also check whether indent/outdent is even possible before doing it.
Currently this is done in a very hacky way (by checking the state of the
indent button), ideally we'd refactor things such that toolbar tools can
listen for keydowns and intercept them, that would make the code much
cleaner and we wouldn't have this problem.

Change-Id: I99885ee4b8a79cd24c4958c188addfc2b0453b03
This commit is contained in:
Catrope 2012-07-07 14:19:14 -07:00
parent ce1f4dac55
commit 5b4554b47f
2 changed files with 22 additions and 18 deletions

View file

@ -133,21 +133,20 @@ ve.ce.Surface.prototype.onKeyDown = function( e ) {
annotations,
annotation;
switch ( e.keyCode ) {
// Indenting list items doesn't work yet, so disable tab handling for now
/*
// Tab Key
case 9:
// If possible, trigger a list indent/outdent
// FIXME this way of checking whether indenting is possible is extremely hacky
// Instead, we should allow toolbar tools to subscribe to and intercept keydowns
if ( $( '.es-toolbarButtonTool-indent' ).is( ':not(.es-toolbarButtonTool-disabled)' ) ) {
e.preventDefault();
// FIXME check if indentation is even possible here, insert literal tab otherwise
ve.ui.IndentationButtonTool.changeListLevel( this.model , 'in' );
if ( e.shiftKey ) {
ve.ui.IndentationButtonTool.outdentListItem( this.model );
} else {
ve.ui.IndentationButtonTool.indentListItem( this.model );
}
}
break;
// Shift + Tab Key
case 16:
e.preventDefault();
// FIXME check if indentation is even possible here
ve.ui.IndentationButtonTool.changeListLevel( this.model , 'out' );
break;
*/
// Left arrow
case 37:
if ( !e.metaKey && !e.altKey && !e.shiftKey && this.model.getSelection().getLength() === 0 ) {

View file

@ -46,8 +46,15 @@ ve.ui.IndentationButtonTool.prototype.onClick = function() {
};
ve.ui.IndentationButtonTool.prototype.indent = function( listItems ) {
var surfaceModel = this.toolbar.getSurfaceView().getModel(),
documentModel = surfaceModel.getDocument(),
ve.ui.IndentationButtonTool.indentListItem( this.toolbar.getSurfaceView().getModel() );
};
ve.ui.IndentationButtonTool.prototype.outdent = function( listItems ) {
ve.ui.IndentationButtonTool.outdentListItem( this.toolbar.getSurfaceView().getModel() );
};
ve.ui.IndentationButtonTool.indentListItem = function( surfaceModel ) {
var documentModel = surfaceModel.getDocument(),
selection = surfaceModel.getSelection(),
groups = documentModel.getCoveredSiblingGroups( selection );
@ -123,9 +130,8 @@ ve.ui.IndentationButtonTool.prototype.indent = function( listItems ) {
}
};
ve.ui.IndentationButtonTool.prototype.outdent = function( listItems ) {
var surfaceModel = this.toolbar.getSurfaceView().getModel(),
documentModel = surfaceModel.getDocument(),
ve.ui.IndentationButtonTool.outdentListItem = function( surfaceModel ) {
var documentModel = surfaceModel.getDocument(),
selection = surfaceModel.getSelection(),
groups = documentModel.getCoveredSiblingGroups( selection );
@ -238,7 +244,6 @@ ve.ui.IndentationButtonTool.prototype.outdent = function( listItems ) {
};
ve.ui.IndentationButtonTool.prototype.updateState = function( annotations, nodes ) {
// FIXME old code, doesn't work
function areListItems( nodes ) {
for( var i = 0; i < nodes.length; i++ ) {
if (