Skip to content

Commit afe53c5

Browse files
authored
fix: Dispatch keyboard events with the workspace they occurred on. (#9137)
* fix: Dispatch keyboard events with the workspace they occurred on. * chore: Add comment warding off would-be refactorers.
1 parent 7df501d commit afe53c5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

core/common.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,28 @@ export function defineBlocks(blocks: {[key: string]: BlockDefinition}) {
320320
* @param e Key down event.
321321
*/
322322
export function globalShortcutHandler(e: KeyboardEvent) {
323-
const mainWorkspace = getMainWorkspace() as WorkspaceSvg;
324-
if (!mainWorkspace) {
325-
return;
323+
// This would ideally just be a `focusedTree instanceof WorkspaceSvg`, but
324+
// importing `WorkspaceSvg` (as opposed to just its type) causes cycles.
325+
let workspace: WorkspaceSvg = getMainWorkspace() as WorkspaceSvg;
326+
const focusedTree = getFocusManager().getFocusedTree();
327+
for (const ws of getAllWorkspaces()) {
328+
if (focusedTree === (ws as WorkspaceSvg)) {
329+
workspace = ws as WorkspaceSvg;
330+
break;
331+
}
326332
}
327333

328334
if (
329335
browserEvents.isTargetInput(e) ||
330-
(mainWorkspace.rendered && !mainWorkspace.isVisible())
336+
!workspace ||
337+
(workspace.rendered && !workspace.isFlyout && !workspace.isVisible())
331338
) {
332339
// When focused on an HTML text input widget, don't trap any keys.
333340
// Ignore keypresses on rendered workspaces that have been explicitly
334341
// hidden.
335342
return;
336343
}
337-
ShortcutRegistry.registry.onKeyDown(mainWorkspace, e);
344+
ShortcutRegistry.registry.onKeyDown(workspace, e);
338345
}
339346

340347
export const TEST_ONLY = {defineBlocksWithJsonArrayInternal};

0 commit comments

Comments
 (0)