Repository navigation
fix(web): honor editableFocus in shortcut conditions #24134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
maria-rcks
merged 2 commits into
pingdotgg:main
from
unmanbearpig:fix/editable-shortcuts
Nov 1, 2026
+110
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { describe, expect, it, vi } from "vite-plus/test"; | ||
| import type { KeybindingCommand } from "@t3tools/contracts"; | ||
| import { compileResolvedKeybindingsConfig } from "@t3tools/shared/keybindings"; | ||
| import { resolveShortcutCommand } from "./keybindings"; | ||
| import * as editableFocus from "./lib/editableFocus"; | ||
|
|
||
| function setupFocus() { | ||
| const editor = new EventTarget(); | ||
| const other = new EventTarget(); | ||
| vi.stubGlobal("document", { activeElement: editor }); | ||
| const focus = vi | ||
| .spyOn(editableFocus, "isEditableFocused") | ||
| .mockImplementation((target) => target === editor); | ||
| return { | ||
| editor, | ||
| other, | ||
| [Symbol.dispose]() { | ||
| focus.mockRestore(); | ||
| vi.unstubAllGlobals(); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function keydown(target?: EventTarget) { | ||
| return { | ||
| key: "k", | ||
| ctrlKey: true, | ||
| metaKey: false, | ||
| altKey: false, | ||
| shiftKey: false, | ||
| ...(target ? { target } : {}), | ||
| }; | ||
| } | ||
|
|
||
| function bindings(command: KeybindingCommand, when = "!editableFocus") { | ||
| return compileResolvedKeybindingsConfig([{ key: "mod+k", command, when }]); | ||
| } | ||
|
|
||
| describe("editable shortcut conditions", () => { | ||
| it.each(["commandPalette.toggle", "sidebar.toggle", "thread.next", "thread.jump.1"] as const)( | ||
| "honors !editableFocus for %s without a caller-provided focus context", | ||
| (command) => { | ||
| using focus = setupFocus(); | ||
| const rules = bindings(command); | ||
|
|
||
| expect( | ||
| resolveShortcutCommand(keydown(focus.editor), rules, { | ||
| platform: "Linux", | ||
| context: { terminalFocus: false }, | ||
| }), | ||
| ).toBeNull(); | ||
| expect(resolveShortcutCommand(keydown(focus.other), rules, { platform: "Linux" })).toBe( | ||
| command, | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| it("uses the active element when a forwarded shortcut has no target", () => { | ||
| using _focus = setupFocus(); | ||
| expect( | ||
| resolveShortcutCommand(keydown(), bindings("commandPalette.toggle"), { platform: "Linux" }), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("honors a positive editableFocus condition", () => { | ||
| using focus = setupFocus(); | ||
| const rules = bindings("commandPalette.toggle", "editableFocus"); | ||
| expect(resolveShortcutCommand(keydown(focus.editor), rules, { platform: "Linux" })).toBe( | ||
| "commandPalette.toggle", | ||
| ); | ||
| expect(resolveShortcutCommand(keydown(focus.other), rules, { platform: "Linux" })).toBeNull(); | ||
| }); | ||
|
|
||
| it("preserves explicit focus overrides", () => { | ||
| using focus = setupFocus(); | ||
| const rules = bindings("commandPalette.toggle"); | ||
|
|
||
| expect( | ||
| resolveShortcutCommand(keydown(focus.editor), rules, { | ||
| platform: "Linux", | ||
| context: { editableFocus: false }, | ||
| }), | ||
| ).toBe("commandPalette.toggle"); | ||
| expect( | ||
| resolveShortcutCommand(keydown(focus.other), rules, { | ||
| platform: "Linux", | ||
| context: { editableFocus: true }, | ||
| }), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("keeps shortcuts without an editable-focus condition active while editing", () => { | ||
| using focus = setupFocus(); | ||
| expect( | ||
| resolveShortcutCommand(keydown(focus.editor), bindings("commandPalette.toggle", "true"), { | ||
| platform: "Linux", | ||
| }), | ||
| ).toBe("commandPalette.toggle"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.