From dad06ef49501764f428608540caa22d2daf4a4de Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 8 Dec 2014 14:49:39 -0800 Subject: [PATCH] Followup 1c04d32d: release saveDialog reference even if closed It's good that we're not trying to close the save dialog if it's not open, but we still need to release our reference to it in that case, otherwise trying to open the save dialog in a new incarnation of the editor will fail. If you opened VE, opened the save dialog, closed it, went back to read mode, opened VE again, and tried to open the save dialog again, it would fail because it tried to open the cached reference to the previous editor's save dialog. Bonus: prevent JS errors in this case by only attaching an onClose handler if the dialog actually opened successfully. If opening the dialog failed, the callback parameter isn't a promise but an OO.ui.Error, and calling .always() causes a JS error. Change-Id: I62d6d3e7cd3df2c29a0c99e2e23bf1aac5187a12 --- .../ve-mw/init/targets/ve.init.mw.ViewPageTarget.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js index be82b2d783..9a6bc96bcf 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -1019,9 +1019,11 @@ ve.init.mw.ViewPageTarget.prototype.tearDownSurface = function () { this.surface.mwTocWidget.teardown(); } - if ( this.saveDialog && this.saveDialog.isOpened() ) { - // If the save dialog is still open (from saving) close it - promises.push( this.saveDialog.close() ); + if ( this.saveDialog ) { + if ( this.saveDialog.isOpened() ) { + // If the save dialog is still open (from saving) close it + promises.push( this.saveDialog.close() ); + } // Release the reference this.saveDialog = null; } @@ -1173,7 +1175,7 @@ ve.init.mw.ViewPageTarget.prototype.showSaveDialog = function () { { dir: this.surface.getModel().getDocument().getLang() } ) // Call onSaveDialogClose() when the save dialog starts closing - .always( function ( opened ) { + .done( function ( opened ) { opened.always( target.onSaveDialogClose.bind( target ) ); } ); }.bind( this ) );