From 91964a48d09bfeaafaafc974b24b026ac366b1a6 Mon Sep 17 00:00:00 2001 From: Catrope Date: Mon, 15 Oct 2012 15:01:39 -0700 Subject: [PATCH] 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 --- modules/ve/dm/ve.dm.DocumentSynchronizer.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/ve/dm/ve.dm.DocumentSynchronizer.js b/modules/ve/dm/ve.dm.DocumentSynchronizer.js index 58257e4f35..eefd621ab0 100644 --- a/modules/ve/dm/ve.dm.DocumentSynchronizer.js +++ b/modules/ve/dm/ve.dm.DocumentSynchronizer.js @@ -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