From 5badd4fcd468f51cdec9855f0366e653f9bb999e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 21 Jun 2021 16:33:19 +0200 Subject: [PATCH] ve.ui.MWBackTool: Avoid using global ve.init.target We have to move the activation logic from a ve.ui.Command to the ve.ui.Tool, as the Command is unable to refer to the Target. Previous attempt: 4984c5ffbbf26d6c274d19924d9bda70442eb1b5 reverted in fb32aa497878e847612b5c467f5a2a385ea58077. Bug: T279313 Change-Id: I3cb74aa5123b67a6c63b8e07ea7f93a6d4a07d4f --- modules/ve-mw/ui/tools/ve.ui.MWBackTool.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/modules/ve-mw/ui/tools/ve.ui.MWBackTool.js b/modules/ve-mw/ui/tools/ve.ui.MWBackTool.js index c2c814841e..120ac002ef 100644 --- a/modules/ve-mw/ui/tools/ve.ui.MWBackTool.js +++ b/modules/ve-mw/ui/tools/ve.ui.MWBackTool.js @@ -18,9 +18,7 @@ ve.ui.MWBackTool.static.group = 'navigation'; ve.ui.MWBackTool.static.icon = 'close'; ve.ui.MWBackTool.static.title = OO.ui.deferMsg( 'visualeditor-backbutton-tooltip' ); -ve.ui.MWBackTool.static.commandName = 'back'; -/** */ ve.ui.MWBackTool.prototype.onUpdateState = function () { // Parent method ve.ui.MWBackTool.super.prototype.onUpdateState.apply( this, arguments ); @@ -29,17 +27,13 @@ ve.ui.MWBackTool.prototype.onUpdateState = function () { this.setDisabled( false ); }; -ve.ui.toolFactory.register( ve.ui.MWBackTool ); +ve.ui.MWBackTool.prototype.onSelect = function () { + // Parent method + ve.ui.MWBackTool.super.prototype.onSelect.apply( this, arguments ); -/** - * Back command - */ -ve.ui.MWBackCommand = function VeUiMWBackCommand() { - // Parent constructor - ve.ui.MWBackCommand.super.call( this, 'back' ); + if ( this.toolbar instanceof ve.ui.TargetToolbar ) { + this.toolbar.target.tryTeardown(); + } }; -OO.inheritClass( ve.ui.MWBackCommand, ve.ui.Command ); -ve.ui.MWBackCommand.prototype.execute = function () { - ve.init.target.tryTeardown(); -}; -ve.ui.commandRegistry.register( new ve.ui.MWBackCommand() ); + +ve.ui.toolFactory.register( ve.ui.MWBackTool );