mirror of
https://github.com/google/blockly.git
synced 2026-01-08 09:30:06 +01:00
fix: Fix bug that prevented using keyboard shortcuts when the DropDownDiv is open. (#9085)
* fix: Fix bug that prevented using keyboard shortcuts when the DropDownDiv is open. * chore: Remove obsolete comment. * Refactor: Remove unreachable null check. * chore: Add tests for handling Escape to dismiss the Widget/DropDownDivs. * chore: Satisfy the linter. * fix: Fix post-merge test failure.
This commit is contained in:
@@ -8,11 +8,13 @@
|
||||
|
||||
import type {Block} from './block.js';
|
||||
import {BlockDefinition, Blocks} from './blocks.js';
|
||||
import * as browserEvents from './browser_events.js';
|
||||
import type {Connection} from './connection.js';
|
||||
import {EventType} from './events/type.js';
|
||||
import * as eventUtils from './events/utils.js';
|
||||
import {getFocusManager} from './focus_manager.js';
|
||||
import {ISelectable, isSelectable} from './interfaces/i_selectable.js';
|
||||
import {ShortcutRegistry} from './shortcut_registry.js';
|
||||
import type {Workspace} from './workspace.js';
|
||||
import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
|
||||
@@ -310,4 +312,29 @@ export function defineBlocks(blocks: {[key: string]: BlockDefinition}) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a key-down on SVG drawing surface. Does nothing if the main workspace
|
||||
* is not visible.
|
||||
*
|
||||
* @internal
|
||||
* @param e Key down event.
|
||||
*/
|
||||
export function globalShortcutHandler(e: KeyboardEvent) {
|
||||
const mainWorkspace = getMainWorkspace() as WorkspaceSvg;
|
||||
if (!mainWorkspace) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
browserEvents.isTargetInput(e) ||
|
||||
(mainWorkspace.rendered && !mainWorkspace.isVisible())
|
||||
) {
|
||||
// When focused on an HTML text input widget, don't trap any keys.
|
||||
// Ignore keypresses on rendered workspaces that have been explicitly
|
||||
// hidden.
|
||||
return;
|
||||
}
|
||||
ShortcutRegistry.registry.onKeyDown(mainWorkspace, e);
|
||||
}
|
||||
|
||||
export const TEST_ONLY = {defineBlocksWithJsonArrayInternal};
|
||||
|
||||
Reference in New Issue
Block a user