mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-24 22:33:34 +00:00
fix(app): match control-letter keybinds
This commit is contained in:
parent
518772c2ba
commit
43900daa7e
2 changed files with 17 additions and 2 deletions
|
|
@ -32,6 +32,14 @@ describe("command keybind helpers", () => {
|
|||
expect(matchKeybind(keybinds, new KeyboardEvent("keydown", { key: ",", ctrlKey: true, altKey: true }))).toBe(false)
|
||||
})
|
||||
|
||||
test("matchKeybind handles control-letter browser key values", () => {
|
||||
const keybinds = parseKeybind("ctrl+l")
|
||||
|
||||
expect(matchKeybind(keybinds, new KeyboardEvent("keydown", { key: "\f", code: "KeyL", ctrlKey: true }))).toBe(
|
||||
true,
|
||||
)
|
||||
})
|
||||
|
||||
test("matchKeybind supports bracket keys", () => {
|
||||
const keybinds = parseKeybind("mod+alt+[, mod+alt+]")
|
||||
const prev = keybinds[0]
|
||||
|
|
|
|||
|
|
@ -53,8 +53,15 @@ function signature(key: string, ctrl: boolean, meta: boolean, shift: boolean, al
|
|||
return `${key}:${mask}`
|
||||
}
|
||||
|
||||
function normalizeEventKey(event: KeyboardEvent) {
|
||||
if (event.ctrlKey && event.key.length === 1 && event.key.charCodeAt(0) <= 0x1f && event.code.startsWith("Key")) {
|
||||
return event.code.slice(3).toLowerCase()
|
||||
}
|
||||
return normalizeKey(event.key)
|
||||
}
|
||||
|
||||
function signatureFromEvent(event: KeyboardEvent) {
|
||||
return signature(normalizeKey(event.key), event.ctrlKey, event.metaKey, event.shiftKey, event.altKey)
|
||||
return signature(normalizeEventKey(event), event.ctrlKey, event.metaKey, event.shiftKey, event.altKey)
|
||||
}
|
||||
|
||||
function isAllowedEditableKeybind(id: string | undefined) {
|
||||
|
|
@ -158,7 +165,7 @@ export function parseKeybind(config: string): Keybind[] {
|
|||
}
|
||||
|
||||
export function matchKeybind(keybinds: Keybind[], event: KeyboardEvent): boolean {
|
||||
const eventKey = normalizeKey(event.key)
|
||||
const eventKey = normalizeEventKey(event)
|
||||
|
||||
for (const kb of keybinds) {
|
||||
const keyMatch = kb.key === eventKey
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue