mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
Fix JS error in DocumentSynchronizer when adding to an empty document
This was reproducible by blanking the entire document (Ctrl+A Delete), then undoing that (Ctrl+Z). AFAIK that's the only way to trigger an insertion on a document that is completely empty. Change-Id: I22252d5972a413dff614880a90c4c6b22e79672d
This commit is contained in:
parent
dac224e110
commit
91964a48d0
|
@ -112,10 +112,12 @@ ve.dm.DocumentSynchronizer.synchronizers.rebuild = function ( action ) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( 'indexInNode' in selection[0] ) {
|
||||
// If the document is empty, selection[0].node will be the document (so no parent)
|
||||
// but we won't get indexInNode either. Detect this and use index=0 in that case.
|
||||
if ( 'indexInNode' in selection[0] || !selection[0].node.getParent() ) {
|
||||
// Insertion
|
||||
parent = selection[0].node;
|
||||
index = selection[0].indexInNode;
|
||||
index = selection[0].indexInNode || 0;
|
||||
numNodes = 0;
|
||||
} else {
|
||||
// Rebuild
|
||||
|
|
Loading…
Reference in a new issue