From 4ce67bb1088e4c8c045174456274c7a9ca0952ab Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 2 Jan 2020 15:12:06 -0800 Subject: [PATCH] Fix moving cursor when block mutates (#3535) * Fix moving cursor when block mutates --- core/block.js | 5 ----- core/mutator.js | 8 ++++---- core/workspace.js | 9 --------- core/workspace_svg.js | 7 +++++++ tests/mocha/gesture_test.js | 4 ++-- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/core/block.js b/core/block.js index 015b2ade6..6622a7089 100644 --- a/core/block.js +++ b/core/block.js @@ -323,11 +323,6 @@ Blockly.Block.prototype.dispose = function(healStack) { this.workspace.removeChangeListener(this.onchangeWrapper_); } - if (this.workspace.keyboardAccessibilityMode) { - // No-op if this is called from the block_svg class. - Blockly.navigation.moveCursorOnBlockDelete(this); - } - this.unplug(healStack); if (Blockly.Events.isEnabled()) { Blockly.Events.fire(new Blockly.Events.BlockDelete(this)); diff --git a/core/mutator.js b/core/mutator.js index c864c9f8d..113c1ab2c 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -376,6 +376,10 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { block.compose(this.rootBlock_); block.initSvg(); block.render(); + + if (Blockly.getMainWorkspace().keyboardAccessibilityMode) { + Blockly.navigation.moveCursorOnBlockMutation(block); + } var newMutationDom = block.mutationToDom(); var newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); if (oldMutation != newMutation) { @@ -390,10 +394,6 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { }, Blockly.BUMP_DELAY); } - if (oldMutation != newMutation && - this.workspace_.keyboardAccessibilityMode) { - Blockly.navigation.moveCursorOnBlockMutation(block); - } // Don't update the bubble until the drag has ended, to avoid moving blocks // under the cursor. if (!this.workspace_.isDragging()) { diff --git a/core/workspace.js b/core/workspace.js index 3f9749a75..a4af7a75d 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -23,8 +23,6 @@ goog.provide('Blockly.Workspace'); -goog.require('Blockly.Cursor'); -goog.require('Blockly.Marker'); goog.require('Blockly.Events'); goog.require('Blockly.utils'); goog.require('Blockly.utils.math'); @@ -111,13 +109,6 @@ Blockly.Workspace = function(opt_options) { * @private */ this.potentialVariableMap_ = null; - - /** - * True if keyboard accessibility mode is on, false otherwise. - * @type {boolean} - * @package - */ - this.keyboardAccessibilityMode = false; }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 74f960750..461e86836 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -155,6 +155,13 @@ Blockly.WorkspaceSvg = function(options, this.themeManager_.subscribeWorkspace(this); this.renderer_.getConstants().refreshTheme(this.getTheme()); + + /** + * True if keyboard accessibility mode is on, false otherwise. + * @type {boolean} + * @package + */ + this.keyboardAccessibilityMode = false; }; Blockly.utils.object.inherits(Blockly.WorkspaceSvg, Blockly.Workspace); diff --git a/tests/mocha/gesture_test.js b/tests/mocha/gesture_test.js index 680bc0bc6..849eb9f23 100644 --- a/tests/mocha/gesture_test.js +++ b/tests/mocha/gesture_test.js @@ -90,8 +90,8 @@ suite('Gesture', function() { }; var ws = Blockly.inject('blocklyDiv', {}); var gesture = new Blockly.Gesture(this.e, ws); - assertFalse(Blockly.getMainWorkspace().keyboardAccessibilityMode); + assertFalse(ws.keyboardAccessibilityMode); gesture.doWorkspaceClick_(event); - assertTrue(Blockly.getMainWorkspace().keyboardAccessibilityMode); + assertTrue(ws.keyboardAccessibilityMode); }); });