mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-12 00:58:44 +00:00
Convert WikitextPasteContextItem to PersistentContextItem
Depends-On: Id2900c2d2c692b611e611b7eee6cacb74a737a8c Change-Id: Ic539a41e8623c4ed12e4fa0e24db826ca967ee5a
This commit is contained in:
parent
8e1c84c0a7
commit
916b7beb22
|
@ -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' );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -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' ),
|
||||
|
|
Loading…
Reference in a new issue