Make Enter in an empty list item unindent

For pressing Enter in an empty list item at the end of a top-level list,
this has the same result as the previous code, but if you're in a nested
list it has the effect of jumping down a level. A previous incarnation
of this change just made Enter insert more list items ad infinitum if
you were in a nested list, but I think this is better.

This fixes a bug where pressing at the end of a nested list inserted a
paragraph in an invalid location

Change-Id: I9c7dbaf29a98f84926ed3a05e71c6294926dfce2
This commit is contained in:
Catrope 2012-07-18 21:05:31 -07:00
parent 5b4554b47f
commit feab4e58a1

View file

@ -719,20 +719,16 @@ ve.ce.Surface.prototype.handleEnter = function( e ) {
node.model.length === 0 // the child is empty
) {
// Enter was pressed in an empty list item.
var list = outermostNode.getModel().getParent();
// Remove the list item
tx = ve.dm.Transaction.newFromRemoval( documentModel, outermostNode.getModel().getOuterRange() );
this.model.change( tx );
// Insert a paragraph
tx = ve.dm.Transaction.newFromInsertion( documentModel, list.getOuterRange().to, emptyParagraph );
// Outdent the list item, which will turn it into a paragraph if it's not in a nested list
// FIXME this is an ugly way to trigger outdent, with a proper API we could do better
ve.ui.IndentationButtonTool.outdentListItem( this.model );
advanceCursor = false;
} else {
// We must process the transaction first because getRelativeContentOffset can't help us yet
tx = ve.dm.Transaction.newFromInsertion( documentModel, selection.from, stack );
this.model.change( tx );
}
}
this.model.change( tx );
// Now we can move the cursor forward
if ( advanceCursor ) {