diff --git a/modules/ve-mw/ce/ve.ce.MWWikitextSurface.js b/modules/ve-mw/ce/ve.ce.MWWikitextSurface.js index c8b3f872e3..9087897caf 100644 --- a/modules/ve-mw/ce/ve.ce.MWWikitextSurface.js +++ b/modules/ve-mw/ce/ve.ce.MWWikitextSurface.js @@ -120,31 +120,21 @@ ve.ce.MWWikitextSurface.prototype.afterPasteInsertExternalData = function ( targ setTimeout( function () { var surface = view.getSurface(), context = surface.getContext(); - // HACK: Directly set the 'relatedSources' result in the context to trick it - // into showing a context at the end of the paste. This context will disappear - // as soon as the selection change as a contextChange will fire. - // TODO: Come up with a method to store this context on the surface model then - // have the LinearContext read it from there. - context.relatedSources = [ { - embeddable: false, - // HACKĀ²: Pass the rich text document and original fragment (which should now cover - // the pasted text) to the context via the otherwise-unused 'model' property. - model: { - doc: pastedDocumentModel, - contextRange: contextRange, - fragment: targetFragment - }, - name: 'wikitextPaste', - type: 'item' - } ]; // Ensure surface is deactivated on mobile so context can be shown (T336073) if ( context.isMobile() ) { surface.getView().deactivate(); } - context.afterContextChange(); + context.addPersistentSource( { + embeddable: false, + name: 'wikitextPaste', + data: { + doc: pastedDocumentModel, + contextRange: contextRange, + fragment: targetFragment + } + } ); surface.getModel().once( 'select', function () { - context.relatedSources = []; - context.afterContextChange(); + context.removePersistentSource( 'wikitextPaste' ); } ); } ); } ); diff --git a/modules/ve-mw/ui/contextitems/ve.ui.MWWikitextPasteContextItem.js b/modules/ve-mw/ui/contextitems/ve.ui.MWWikitextPasteContextItem.js index ca978ac31c..b5381438a7 100644 --- a/modules/ve-mw/ui/contextitems/ve.ui.MWWikitextPasteContextItem.js +++ b/modules/ve-mw/ui/contextitems/ve.ui.MWWikitextPasteContextItem.js @@ -8,11 +8,11 @@ * Context item shown after a rich text paste. * * @class - * @extends ve.ui.LinearContextItem + * @extends ve.ui.PersistentContextItem * * @constructor * @param {ve.ui.LinearContext} context Context the item is in - * @param {ve.dm.Model} model Model the item is related to + * @param {Object} [data] Extra data * @param {Object} [config] */ ve.ui.MWWikitextPasteContextItem = function VeUiMWWikitextPasteContextItem() { @@ -25,7 +25,7 @@ ve.ui.MWWikitextPasteContextItem = function VeUiMWWikitextPasteContextItem() { /* Inheritance */ -OO.inheritClass( ve.ui.MWWikitextPasteContextItem, ve.ui.LinearContextItem ); +OO.inheritClass( ve.ui.MWWikitextPasteContextItem, ve.ui.PersistentContextItem ); /* Static Properties */ @@ -35,17 +35,15 @@ ve.ui.MWWikitextPasteContextItem.static.icon = 'wikiText'; ve.ui.MWWikitextPasteContextItem.static.label = OO.ui.deferMsg( 'visualeditor-wikitextconvert-title' ); -ve.ui.MWWikitextPasteContextItem.static.editable = false; - /* Methods */ /** * @inheritdoc */ ve.ui.MWWikitextPasteContextItem.prototype.renderBody = function () { - var fragment = this.model.fragment, - doc = this.model.doc, - contextRange = this.model.contextRange; + var fragment = this.data.fragment, + doc = this.data.doc, + contextRange = this.data.contextRange; var convertButton = new OO.ui.ButtonWidget( { label: ve.msg( 'visualeditor-wikitextconvert-convert' ),