jenkins-bot has submitted this change and it was merged.

Change subject: Don't change config during toolbar setup
......................................................................


Don't change config during toolbar setup

Problem: When the toolbar is created twice with the same config object,
the second time around the tools are still bound to the old surface

Reason: The tool config is overwritten such that symbolic names of tools
are replaced with instances of tools, bound to a specific surface. The
second time around, the creation fails (silently in a try-catch) and then
the already translated list of tools is used to create a new toolbar
filled with old tools still bound to the wrong surface.

Solution: Leave the config object alone, and instead build a new list of
tool instances while iterating through tool names.

Bonus: Don't fail silently. Using a try-catch to detect whether a
requested tool is supported masks other errors, and is evil. Instead,
just do a lookup and skip tools in which the lookup's result is falsey.

Change-Id: Ic43ec29173e556592bb3db9399ff83787e0a6857
---
M modules/ve/ui/ve.ui.Toolbar.js
1 file changed, 7 insertions(+), 6 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/ui/ve.ui.Toolbar.js b/modules/ve/ui/ve.ui.Toolbar.js
index 9b7be98..fe70b32 100644
--- a/modules/ve/ui/ve.ui.Toolbar.js
+++ b/modules/ve/ui/ve.ui.Toolbar.js
@@ -67,17 +67,18 @@
  * @param {Object[]} config List of tool group configurations
  */
 ve.ui.Toolbar.prototype.setup = function ( config ) {
-       var i, j, group, tools;
+       var i, j, group, items, tools;
 
        for ( i = 0; i < config.length; i++ ) {
-               tools = config[i].items;
+               items = config[i].items;
+               tools = [];
                group = new ve.ui.ToolGroup( this, { '$$': this.$$ } );
 
                // Add tools
-               for ( j = 0; j < tools.length; j++ ) {
-                       try {
-                               tools[j] = ve.ui.toolFactory.create( tools[j], 
this );
-                       } catch( e ) {}
+               for ( j = 0; j < items.length; j++ ) {
+                       if ( ve.ui.toolFactory.lookup( items[j] ) ) {
+                               tools.push( ve.ui.toolFactory.create( items[j], 
this ) );
+                       }
                }
                group.addItems( tools );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/79951
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic43ec29173e556592bb3db9399ff83787e0a6857
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to