mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-27 04:06:51 +00:00
Pressing enter in a list with no nearby content creates a paragraph
Currently we assume getNearestContentOffset will give us something sane however it can return -1 when there is no nearby content and so an exception is thrown. In this case we have to create an empty paragraph to place the cursor in. Change-Id: Ic6c19da881e47ff6be45cdaa4b71bfcc1c654796
This commit is contained in:
parent
519e54d463
commit
456c97d912
|
@ -1658,13 +1658,20 @@ ve.ce.Surface.prototype.handleEnter = function ( e ) {
|
|||
|
||||
// Now we can move the cursor forward
|
||||
if ( advanceCursor ) {
|
||||
this.model.setSelection(
|
||||
new ve.Range( documentModel.data.getRelativeContentOffset( selection.from, 1 ) )
|
||||
);
|
||||
cursor = documentModel.data.getRelativeContentOffset( selection.from, 1 );
|
||||
} else {
|
||||
this.model.setSelection(
|
||||
new ve.Range( documentModel.data.getNearestContentOffset( selection.from ) )
|
||||
cursor = documentModel.data.getNearestContentOffset( selection.from );
|
||||
}
|
||||
if ( cursor === -1 ) {
|
||||
// Cursor couldn't be placed in a nearby content node, so create an empty paragraph
|
||||
this.model.change(
|
||||
ve.dm.Transaction.newFromInsertion(
|
||||
documentModel, selection.from, emptyParagraph
|
||||
)
|
||||
);
|
||||
this.model.setSelection( new ve.Range( selection.from + 1 ) );
|
||||
} else {
|
||||
this.model.setSelection( new ve.Range( cursor ) );
|
||||
}
|
||||
// Reset and resume polling
|
||||
this.surfaceObserver.clear();
|
||||
|
|
|
@ -312,6 +312,20 @@ QUnit.test( 'handleEnter', function ( assert ) {
|
|||
},
|
||||
'expectedRange': new ve.Range( 1 ),
|
||||
'msg': 'Enter in an empty list at start of document destroys it and moves to next paragraph'
|
||||
},
|
||||
{
|
||||
'html': emptyList,
|
||||
'range': new ve.Range( 3 ),
|
||||
'operations': ['enter'],
|
||||
'expectedData': function ( data ) {
|
||||
data.splice(
|
||||
0, 6,
|
||||
{ 'type': 'paragraph' },
|
||||
{ 'type': '/paragraph' }
|
||||
);
|
||||
},
|
||||
'expectedRange': new ve.Range( 1 ),
|
||||
'msg': 'Enter in an empty list with no adjacent content destroys it and creates a paragraph'
|
||||
}
|
||||
];
|
||||
|
||||
|
|
Loading…
Reference in a new issue