diff --git a/src/navigation.ts b/src/navigation.ts index d64a9024..ee5e86eb 100644 --- a/src/navigation.ts +++ b/src/navigation.ts @@ -73,12 +73,6 @@ export class Navigation { */ protected passiveFocusIndicator: PassiveFocus = new PassiveFocus(); - /** - * The node that has passive focus when the cursor has moved to the flyout - * or toolbox; null if the cursor is moving around the main workspace. - */ - protected markedNode: Blockly.ASTNode | null = null; - /** * Constructor for keyboard navigation. */ @@ -418,9 +412,12 @@ export class Navigation { if (!toolbox) { return; } + const cursor = workspace.getCursor(); + if (cursor) { + this.passiveFocusIndicator.show(cursor.getCurNode()); + cursor.hide(); + } - this.markAtCursor(workspace); - workspace.getCursor()?.hide(); this.setState(workspace, Constants.STATE.TOOLBOX); this.resetFlyout(workspace, false /* shouldHide */); @@ -443,8 +440,11 @@ export class Navigation { * @param workspace The workspace the flyout is on. */ focusFlyout(workspace: Blockly.WorkspaceSvg) { - workspace.getCursor()?.hide(); - this.markAtCursor(workspace); + const cursor = workspace.getCursor(); + if (cursor) { + this.passiveFocusIndicator.show(cursor.getCurNode()); + cursor.hide(); + } const flyout = workspace.getFlyout(); this.setState(workspace, Constants.STATE.FLYOUT); @@ -482,6 +482,9 @@ export class Navigation { this.resetFlyout(workspace, reset); this.setState(workspace, Constants.STATE.WORKSPACE); this.setCursorOnWorkspaceFocus(workspace, keepCursorPosition); + + this.passiveFocusIndicator.hide(); + workspace.getCursor()?.draw(); } /** @@ -505,12 +508,6 @@ export class Navigation { return; } - if (this.markedNode) { - cursor.setCurNode(this.markedNode); - this.removeMark(workspace); - return; - } - const disposed = cursor.getCurNode()?.getSourceBlock()?.disposed; if (cursor.getCurNode() && !disposed && keepPosition) { // Retain the cursor's previous position since it's set, but only if not @@ -555,13 +552,14 @@ export class Navigation { * the block will be placed on. */ insertFromFlyout(workspace: Blockly.WorkspaceSvg) { + const stationaryNode = workspace.getCursor()?.getCurNode(); const newBlock = this.createNewBlock(workspace); if (!newBlock) return; - if (this.markedNode) { + if (stationaryNode) { if ( !this.tryToConnectNodes( workspace, - this.markedNode, + stationaryNode, Blockly.ASTNode.createBlockNode(newBlock)!, ) ) { @@ -575,7 +573,6 @@ export class Navigation { workspace .getCursor()! .setCurNode(Blockly.ASTNode.createBlockNode(newBlock)!); - this.removeMark(workspace); } /** @@ -628,26 +625,6 @@ export class Navigation { } } - /** - * Connects the location of the marked node and the location of the cursor. - * No-op if the marked node or cursor node are null. - * - * @param workspace The main workspace. - * @returns True if the cursor and marker locations were connected, - * false otherwise. - */ - connectMarkerAndCursor(workspace: Blockly.WorkspaceSvg): boolean { - const cursorNode = workspace.getCursor()!.getCurNode(); - - if (this.markedNode && cursorNode) { - if (this.tryToConnectNodes(workspace, this.markedNode, cursorNode)) { - this.removeMark(workspace); - return true; - } - } - return false; - } - /** * Tries to intelligently connect the blocks or connections * represented by the given nodes, based on node types and locations. @@ -1082,32 +1059,6 @@ export class Navigation { } } - /** - * Moves the passive focus indicator to the cursor's current location. - * - * @param workspace The workspace. - */ - markAtCursor(workspace: Blockly.WorkspaceSvg) { - const cursor = workspace.getCursor()!; - this.markedNode = cursor.getCurNode(); - - // Although it seems like this should never happen, the typings are wrong - // in the base Marker class and this can therefore be null. - if (this.markedNode) { - this.passiveFocusIndicator.show(this.markedNode); - } - } - - /** - * Removes the passive focus indicator from its current location and hides it. - * - * @param workspace The workspace. - */ - removeMark(workspace: Blockly.WorkspaceSvg) { - this.passiveFocusIndicator.hide(); - this.markedNode = null; - } - /** * Enables accessibility mode. * @@ -1135,7 +1086,6 @@ export class Navigation { workspace.keyboardAccessibilityMode ) { workspace.keyboardAccessibilityMode = false; - this.markAtCursor(workspace); workspace.getCursor()!.hide(); if (this.getFlyoutCursor(workspace)) { this.getFlyoutCursor(workspace)!.hide(); @@ -1250,7 +1200,6 @@ export class Navigation { * @param workspace The active workspace. */ openToolboxOrFlyout(workspace: Blockly.WorkspaceSvg) { - this.markAtCursor(workspace); if (workspace.getToolbox()) { this.focusToolbox(workspace); } else { @@ -1390,7 +1339,6 @@ export class Navigation { Blockly.ASTNode.createBlockNode(block)!, ); } - this.removeMark(workspace); return true; } Blockly.Events.setGroup(false);