From 301c84bda4bc02fb8c652aaffb9231704af94748 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 19 Aug 2021 15:44:35 +0200 Subject: [PATCH] Call focusPart() only once in MWTemplateDialog.onReplacePart() This merges all code-paths that re-select a part (i.e. an input widget on the right side of the template dialog). Note there is an edge-case that actually changes with this patch. When a page is removed, and creating a new page fails, there is an `if ( page )` check. Before, the behavior was that nothing gets selected in this case. After this change the behavior is the same as if a page was removed: the closest one gets selected. Not only does this make more sense. The `if` is only a fail-safe anyway and should not result in different behavior. Bug: T288827 Change-Id: Ibb0260587588fb51a876658b16a81c5a73371dc4 --- modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js index 03fe295677..e14e3bb4c8 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js @@ -125,7 +125,7 @@ ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) { this.bookletLayout.addPages( [ page ], this.transclusionModel.getIndex( added ) ); if ( reselect ) { // Use added page instead of closest page - this.transclusions.focusPart( added.getId() ); + reselect = added.getId(); } if ( added instanceof ve.dm.MWTemplateModel ) { @@ -146,13 +146,15 @@ ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) { if ( names.length ) { // Focus the first element when parameters are present - this.transclusions.focusPart( added.getParameter( names[ 0 ] ).getId() ); + reselect = added.getParameter( names[ 0 ] ).getId(); } else if ( shouldAddPlaceholder && !this.isNewSidebar ) { page.addPlaceholderParameter(); } } } - } else if ( reselect ) { + } + + if ( reselect ) { this.transclusions.focusPart( reselect ); }