Merge "Fix switching without changes"

This commit is contained in:
jenkins-bot 2019-04-30 19:37:03 +00:00 committed by Gerrit Code Review
commit d85062d1d1
4 changed files with 22 additions and 29 deletions

View file

@ -321,7 +321,7 @@ ve.init.mw.DesktopArticleTarget.prototype.loadSuccess = function () {
windowManager.destroy();
if ( data && data.action === 'prefer-wt' ) {
target.switchToWikitextEditor( true, false );
target.switchToWikitextEditor( false );
} else if ( data && data.action === 'multi-tab' ) {
location.reload();
}
@ -715,7 +715,7 @@ ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( code, errorDetai
} else {
// TODO: Some sort of progress bar?
target.wikitextFallbackLoading = true;
target.switchToWikitextEditor( true, false );
target.switchToWikitextEditor( false );
}
} );
} else {
@ -1512,7 +1512,7 @@ ve.init.mw.DesktopArticleTarget.prototype.onUnload = function () {
/**
* @inheritdoc
*/
ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = function ( discardChanges, modified ) {
ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = function ( modified ) {
var uri, oldId, prefPromise,
target = this;
@ -1522,16 +1522,14 @@ ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = funct
oldId = mw.config.get( 'wgRevisionId' ) || $( 'input[name=parentRevId]' ).val();
prefPromise = mw.libs.ve.setEditorPreference( 'wikitext' );
if ( discardChanges ) {
if ( modified ) {
ve.track( 'mwedit.abort', { type: 'switchwithout', mechanism: 'navigate', mode: 'visual' } );
} else {
ve.track( 'mwedit.abort', { type: 'switchnochange', mechanism: 'navigate', mode: 'visual' } );
}
if ( !modified ) {
ve.track( 'mwedit.abort', { type: 'switchnochange', mechanism: 'navigate', mode: 'visual' } );
this.submitting = true;
prefPromise.done( function () {
uri = target.viewUri.clone().extend( {
action: 'edit',
// No changes, safe to stay in section mode
section: target.section,
veswitched: 1
} );
if ( oldId ) {

View file

@ -379,13 +379,13 @@ ve.init.mw.MobileArticleTarget.prototype.loadFail = function ( key, text ) {
ve.init.mw.MobileArticleTarget.prototype.editSource = function () {
var modified = this.fromEditedState || this.getSurface().getModel().hasBeenModified();
this.switchToWikitextEditor( false, modified );
this.switchToWikitextEditor( modified );
};
/**
* @inheritdoc
*/
ve.init.mw.MobileArticleTarget.prototype.switchToWikitextEditor = function ( discardChanges, modified ) {
ve.init.mw.MobileArticleTarget.prototype.switchToWikitextEditor = function ( modified ) {
var dataPromise;
if ( modified ) {
dataPromise = this.getWikitextDataPromiseForDoc( modified ).then( function ( response ) {

View file

@ -1201,10 +1201,8 @@ ve.init.mw.ArticleTarget.prototype.clearState = function () {
ve.init.mw.ArticleTarget.prototype.editSource = function () {
var modified = this.fromEditedState || this.getSurface().getModel().hasBeenModified();
if ( ve.init.target.isModeAvailable( 'source' ) ) {
this.switchToWikitextEditor( false, modified );
} else if ( !modified ) {
this.switchToWikitextEditor( true, modified );
if ( ve.init.target.isModeAvailable( 'source' ) || !modified ) {
this.switchToWikitextEditor( modified );
} else {
ve.ui.actionFactory.create( 'window', this.getSurface() )
.open( 'wikitextswitchconfirm', { target: this } );
@ -2280,13 +2278,11 @@ ve.init.mw.ArticleTarget.prototype.maybeShowWelcomeDialog = function () {
.closed.then( function ( data ) {
target.welcomeDialogPromise.resolve();
target.welcomeDialog = null;
// switchToWikitextEditor and switchToVisualEditor are actually
// only defined in subclasses :/
if ( data && data.action === 'switch-wte' ) {
// TODO: Make this work on mobile - right now we can only
// get away with it because the button which triggers this
// action is hidden on mobile
target.switchToWikitextEditor( true, true );
target.switchToWikitextEditor( false );
} else if ( data && data.action === 'switch-ve' ) {
target.switchToVisualEditor();
}
@ -2315,20 +2311,20 @@ ve.init.mw.ArticleTarget.prototype.maybeShowWelcomeDialog = function () {
/**
* Switches to the wikitext editor, either keeping (default) or discarding changes.
*
* @param {boolean} [discardChanges] Whether to discard changes or not.
* @param {boolean} [modified] Whether there were any changes at all.
* @param {boolean} [leaveVE] Leave VE, even if source mode is available
*/
ve.init.mw.ArticleTarget.prototype.switchToWikitextEditor = function ( discardChanges, modified, leaveVE ) {
ve.init.mw.ArticleTarget.prototype.switchToWikitextEditor = function ( modified ) {
var dataPromise,
target = this;
// When switching we always pass the full page as changes in visual section mode
// When switching with changes we always pass the full page as changes in visual section mode
// can still affect the whole document (e.g. removing a reference)
this.section = null;
if ( modified ) {
this.section = null;
}
if ( ve.init.target.isModeAvailable( 'source' ) && !leaveVE ) {
if ( discardChanges ) {
if ( ve.init.target.isModeAvailable( 'source' ) ) {
if ( !modified ) {
dataPromise = mw.libs.ve.targetLoader.requestPageData( 'source', this.getPageName(), {
sessionStore: true,
section: this.section,
@ -2338,7 +2334,7 @@ ve.init.mw.ArticleTarget.prototype.switchToWikitextEditor = function ( discardCh
function ( response ) { return response; },
function () {
// TODO: Some sort of progress bar?
target.switchToWikitextEditor( discardChanges, modified, true );
target.switchToFallbackWikitextEditor( modified );
// Keep everything else waiting so our error handler can do its business
return $.Deferred().promise();
}
@ -2348,7 +2344,7 @@ ve.init.mw.ArticleTarget.prototype.switchToWikitextEditor = function ( discardCh
}
this.reloadSurface( 'source', dataPromise );
} else {
this.switchToFallbackWikitextEditor( discardChanges, modified );
this.switchToFallbackWikitextEditor( modified );
}
};
@ -2379,7 +2375,6 @@ ve.init.mw.ArticleTarget.prototype.getWikitextDataPromiseForDoc = function ( mod
/**
* Switches to the fallback wikitext editor, either keeping (default) or discarding changes.
*
* @param {boolean} [discardChanges] Whether to discard changes or not.
* @param {boolean} [modified] Whether there were any changes at all.
*/
ve.init.mw.ArticleTarget.prototype.switchToFallbackWikitextEditor = function () {

View file

@ -56,7 +56,7 @@ ve.ui.MWWikitextSwitchConfirmDialog.prototype.getActionProcess = function ( acti
return new OO.ui.Process( function () {
this.getActions().setAbilities( { cancel: false } );
this.getActions().get()[ 1 ].pushPending();
this.target.switchToWikitextEditor( false, true );
this.target.switchToWikitextEditor( true );
}, this );
} else if ( action === 'cancel' ) {
return new OO.ui.Process( function () {