diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js index 77c2105987..3eab17a568 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -489,7 +489,7 @@ ve.init.mw.DesktopArticleTarget.prototype.setSurface = function ( surface ) { }; /** - * Setup new section inputs if required + * Setup new section input for a surface, if required * * @param {ve.ui.Surface} surface Surface */ @@ -510,32 +510,21 @@ ve.init.mw.DesktopArticleTarget.prototype.setupNewSection = function ( surface ) if ( this.currentUri.query.preloadtitle ) { this.sectionTitle.setValue( this.currentUri.query.preloadtitle ); } + surface.once( 'destroy', this.teardownNewSection.bind( this, surface ) ); } }; /** * Teardown new section inputs */ -ve.init.mw.DesktopArticleTarget.prototype.teardownNewSection = function () { - if ( this.getSurface() ) { - this.getSurface().setPlaceholder( '' ); - } +ve.init.mw.DesktopArticleTarget.prototype.teardownNewSection = function ( surface ) { + surface.setPlaceholder( '' ); if ( this.sectionTitle ) { this.sectionTitle.$element.remove(); this.sectionTitle = null; } }; -/** - * @inheritdoc - */ -ve.init.mw.DesktopArticleTarget.prototype.clearSurfaces = function () { - this.teardownNewSection(); - - // Parent method - ve.init.mw.DesktopArticleTarget.super.prototype.clearSurfaces.apply( this, arguments ); -}; - /** * Determines whether we want to switch to view mode or not (displaying a dialog if necessary) * Then, if we do, actually switches to view mode. @@ -560,7 +549,6 @@ ve.init.mw.DesktopArticleTarget.prototype.deactivate = function ( noDialog, trac if ( this.editingTabDialog ) { this.editingTabDialog.close(); } - this.teardownNewSection(); this.editingTabDialog = null; if ( noDialog || this.activating || !this.edited ) {