Skip to content
1 change: 0 additions & 1 deletion src/navigation_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

import './gesture_monkey_patch';
import './toolbox_monkey_patch';

import * as Blockly from 'blockly/core';
import {
Expand Down
14 changes: 14 additions & 0 deletions src/toolbox_monkey_patch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Installs a Toolbox-specific monkey-patch. Note that this must be installed
* before any Toolboxes are registered for key bindings.
*/
export declare function install(): void;

/** Uninstalls the Toolbox-specific monkey-patch. */
export declare function uninstall(): void;
19 changes: 16 additions & 3 deletions src/toolbox_monkey_patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@

import * as Blockly from 'blockly/core';

Blockly.Toolbox.prototype.onKeyDown_ = function () {
// Do nothing since keyboard functionality should be entirely handled by the
// keyboard navigation plugin.
let oldOnKeyDownHandler = null;

export function install() {
oldOnKeyDownHandler = Blockly.Toolbox.prototype.onKeyDown_;
Blockly.Toolbox.prototype.onKeyDown_ = function () {
// Do nothing since keyboard functionality should be entirely handled by the
// keyboard navigation plugin.
};
};

export function uninstall() {
if (!oldOnKeyDownHandler) {
throw new Error("Trying to dispose non-inited monkey patch.");
}
Blockly.Toolbox.prototype.onKeyDown_ = oldOnKeyDownHandler;
oldOnKeyDownHandler = null;
};
2 changes: 2 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {javascriptGenerator} from 'blockly/javascript';
// @ts-expect-error No types in js file
import {load} from './loadTestBlocks';
import {runCode, registerRunCodeShortcut} from './runCode';
import * as ToolboxMonkeyPatch from '../src/toolbox_monkey_patch';

/**
* Parse query params for inject and navigation options and update
Expand Down Expand Up @@ -83,6 +84,7 @@ function createWorkspace(): Blockly.WorkspaceSvg {
renderer,
};
const blocklyDiv = document.getElementById('blocklyDiv')!;
ToolboxMonkeyPatch.install();
const workspace = Blockly.inject(blocklyDiv, injectOptions);

const navigationOptions = {
Expand Down