Jforrester has uploaded a new change for review. https://gerrit.wikimedia.org/r/279532
Change subject: SurfaceFramgent: Guard against tx.getModifiedRange returning null ...................................................................... SurfaceFramgent: Guard against tx.getModifiedRange returning null Bug: T130847 Change-Id: If3785843b0ae15a52a65fb4def60fddb338cc05f --- M src/dm/ve.dm.SurfaceFragment.js 1 file changed, 12 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/32/279532/1 diff --git a/src/dm/ve.dm.SurfaceFragment.js b/src/dm/ve.dm.SurfaceFragment.js index 041a2d3..04ab04d 100644 --- a/src/dm/ve.dm.SurfaceFragment.js +++ b/src/dm/ve.dm.SurfaceFragment.js @@ -720,7 +720,8 @@ * @chainable */ ve.dm.SurfaceFragment.prototype.insertContent = function ( content, annotate ) { - var i, l, lines, annotations, tx, offset, newRange; + var i, l, lines, annotations, tx, offset, newRange, + doc = this.getDocument(); if ( !( this.selection instanceof ve.dm.LinearSelection ) ) { return this; @@ -756,21 +757,17 @@ // TODO T126021: Don't reach into properties of document // FIXME T126022: the logic we actually need for annotating inserted content // correctly is MUCH more complicated - annotations = this.document.data + annotations = doc.data .getAnnotationsFromOffset( offset === 0 ? 0 : offset - 1 ); } if ( annotations && annotations.getLength() > 0 ) { ve.dm.Document.static.addAnnotationsToData( content, annotations ); } - tx = ve.dm.Transaction.newFromInsertion( - this.document, - offset, - content - ); + tx = ve.dm.Transaction.newFromInsertion( doc, offset, content ); // Set the range to cover the inserted content; the offset translation will be wrong // if newFromInsertion() decided to move the insertion point newRange = tx.getModifiedRange(); - this.change( tx, new ve.dm.LinearSelection( this.getDocument(), newRange ) ); + this.change( tx, newRange ? new ve.dm.LinearSelection( doc, newRange ) : new ve.dm.NullSelection( doc ) ); } return this; @@ -801,11 +798,12 @@ * at a different offset if that is needed to make the document balanced. * * @method - * @param {ve.dm.Document} doc Document to insert + * @param {ve.dm.Document} newDoc Document to insert * @chainable */ -ve.dm.SurfaceFragment.prototype.insertDocument = function ( doc ) { - var tx, newRange; +ve.dm.SurfaceFragment.prototype.insertDocument = function ( newDoc ) { + var tx, newRange, + doc = this.getDocument(); if ( !( this.selection instanceof ve.dm.LinearSelection ) ) { return this; @@ -816,14 +814,14 @@ } tx = new ve.dm.Transaction.newFromDocumentInsertion( - this.getDocument(), + doc, this.getSelection().getRange().start, - doc + newDoc ); // Set the range to cover the inserted content; the offset translation will be wrong // if newFromInsertion() decided to move the insertion point newRange = tx.getModifiedRange(); - this.change( tx, new ve.dm.LinearSelection( this.getDocument(), newRange ) ); + this.change( tx, newRange ? new ve.dm.LinearSelection( doc, newRange ) : new ve.dm.NullSelection( doc ) ); return this; }; -- To view, visit https://gerrit.wikimedia.org/r/279532 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If3785843b0ae15a52a65fb4def60fddb338cc05f Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: wmf/1.27.0-wmf.18 Gerrit-Owner: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits