Adjust newNode range and fallback in MWImageModel

When inserting a new node, get the proper fragment range and ask
for the node from within the search loop. Also added a fallback
for the case that the node wasn't found, and a caption cannot
be added.

Change-Id: Ic19d9b1cd2739435137f633de09a13b25a11a0cb
This commit is contained in:
Moriel Schottlender 2014-05-21 01:49:12 -04:00 committed by Mooeypoo
parent 7d228673bb
commit fad534ee4b

View file

@ -243,7 +243,6 @@ ve.dm.MWImageModel.prototype.insertImageNode = function ( fragment ) {
// Insert the new image
coveredNodes = fragment
.collapseRangeToEnd()
.insertContent( contentToInsert )
.getCoveredNodes();
@ -254,6 +253,7 @@ ve.dm.MWImageModel.prototype.insertImageNode = function ( fragment ) {
coveredNodes[i].node.type === 'mwInlineImage'
) {
newNodeRange = coveredNodes[i].nodeOuterRange;
newNode = coveredNodes[i].node;
break;
}
}
@ -261,10 +261,9 @@ ve.dm.MWImageModel.prototype.insertImageNode = function ( fragment ) {
// Select the new node (without extras)
newFragment = surfaceModel.getFragment( newNodeRange );
newFragment.select();
newNode = newFragment.getSelectedNode();
// Check if there should be a caption
if ( newNode.getType() === 'mwBlockImage' ) {
if ( newNode && newNode.getType() === 'mwBlockImage' ) {
if ( this.getCaptionDocument().data.getLength() > 4 ) {
// Add contents of new caption