From b4a0b5f84cefc6d991dd96d742a20dfce7f6a232 Mon Sep 17 00:00:00 2001
From: Eric Rosenbaum <eric.rosenbaum@gmail.com>
Date: Thu, 5 Oct 2017 15:52:15 -0400
Subject: [PATCH] Use a more public way of set selected category

---
 src/containers/blocks.jsx | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/src/containers/blocks.jsx b/src/containers/blocks.jsx
index 77a069e59..345d21e26 100644
--- a/src/containers/blocks.jsx
+++ b/src/containers/blocks.jsx
@@ -76,14 +76,11 @@ class Blocks extends React.Component {
         if (prevProps.toolboxXML !== this.props.toolboxXML) {
             const selectedCategoryName = this.workspace.toolbox_.getSelectedItem().name_;
             this.workspace.updateToolbox(this.props.toolboxXML);
-            // Blockly throws if we don't select a category after updating the toolbox.
-            /** @TODO Find a way to avoid the exception without accessing private properties. */
-            this.setToolboxSelectedItemByName(selectedCategoryName);
+            this.workspace.toolbox_.setSelectedCategoryByName(selectedCategoryName);
         }
         if (this.props.isVisible === prevProps.isVisible) {
             return;
         }
-
         // @todo hack to resize blockly manually in case resize happened while hidden
         // @todo hack to reload the workspace due to gui bug #413
         if (this.props.isVisible) { // Scripts tab
@@ -99,20 +96,6 @@ class Blocks extends React.Component {
         this.detachVM();
         this.workspace.dispose();
     }
-    /**
-     * Select a particular category in the toolbox by specifying the category name.
-     * This is a workaround for a bug: @see {@link componentDidUpdate} above.
-     * @TODO Remove this or reimplement using only public APIs.
-     * @param {string} name - the name of the category to select.
-     */
-    setToolboxSelectedItemByName (name) {
-        const categories = this.workspace.toolbox_.categoryMenu_.categories_;
-        for (let i = 0; i < categories.length; i++) {
-            if (categories[i].name_ === name) {
-                this.workspace.toolbox_.setSelectedItem(categories[i]);
-            }
-        }
-    }
     attachVM () {
         this.workspace.addChangeListener(this.props.vm.blockListener);
         this.flyoutWorkspace = this.workspace
-- 
GitLab