Merge "DesktopArticleTarget.init: Wait for deactivating to finish before activating"

This commit is contained in:
jenkins-bot 2022-04-08 08:49:55 +00:00 committed by Gerrit Code Review
commit 82051a35d3
2 changed files with 19 additions and 12 deletions

View file

@ -32,6 +32,7 @@ ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config
this.onUnloadHandler = this.onUnload.bind( this );
this.activating = false;
this.deactivating = false;
this.deactivatingDeferred = null;
this.recreating = false;
this.activatingDeferred = null;
this.toolbarSetupDeferred = null;
@ -575,8 +576,6 @@ ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism )
saveDialogPromise = ve.createDeferred().resolve().promise(),
target = this;
this.emit( 'deactivate' );
// Event tracking
var abortType, abortedMode;
if ( trackMechanism ) {
@ -596,10 +595,13 @@ ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism )
// Cancel activating, start deactivating
this.deactivating = true;
this.deactivatingDeferred = ve.createDeferred();
this.activating = false;
this.activatingDeferred.reject();
$( 'html' ).addClass( 've-deactivating' ).removeClass( 've-activated ve-active' );
this.emit( 'deactivate' );
// Restore TemplateStyles of the original content
// (We do this here because toggling 've-active' class above displays it)
this.$editableContent.find( 'style[data-mw-deduplicate^="TemplateStyles:"]' ).prop( 'disabled', false );
@ -642,15 +644,16 @@ ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism )
target.initialEditSummary = new mw.Uri().query.summary;
target.editSummaryValue = null;
target.deactivating = false;
$( 'html' ).removeClass( 've-deactivating' );
// Move original content back out of the target
target.$element.parent().append( target.$originalContent.children() );
$( '.ve-init-mw-desktopArticleTarget-uneditableContent' )
.removeClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
target.deactivating = false;
target.deactivatingDeferred.resolve();
$( 'html' ).removeClass( 've-deactivating' );
// Event tracking
if ( trackMechanism ) {
ve.track( 'mwedit.abort', {

View file

@ -548,15 +548,19 @@
if ( tempWikitextEditor ) {
syncTempWikitextEditor();
}
var activatePromise = target.activate( dataPromise );
// toolbarSetupDeferred resolves slightly before activatePromise, use done
// to run in the same paint cycle as the VE toolbar being drawn
target.toolbarSetupDeferred.done( function () {
hideToolbarPlaceholder();
var deactivating = target.deactivatingDeferred || $.Deferred().resolve();
return deactivating.then( function () {
var activatePromise = target.activate( dataPromise );
// toolbarSetupDeferred resolves slightly before activatePromise, use done
// to run in the same paint cycle as the VE toolbar being drawn
target.toolbarSetupDeferred.done( function () {
hideToolbarPlaceholder();
} );
return activatePromise;
} );
return activatePromise;
} )
.then( function () {
if ( mode === 'visual' ) {