Skip to content

Commit 9b9c62c

Browse files
committed
Update is_alt_pressed state detection to exclude other modifier keys
- pressing 'alt' properly highlights actions like changing edit format. the issue is that combination of keys e.g. alt + shift, should cancel these highlights.
1 parent d79168a commit 9b9c62c

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎apps/editor/src/views/panel/frontend/Main/MainView/components/Header/hooks/use-keyboard-shortcuts.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export const use_keyboard_shortcuts = ({
2929

3030
useEffect(() => {
3131
const handle_key_down = (event: KeyboardEvent) => {
32-
if (event.key == 'Alt') set_is_alt_pressed(true)
32+
set_is_alt_pressed(
33+
event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey
34+
)
3335

3436
if (is_disabled) return
3537

@@ -54,7 +56,9 @@ export const use_keyboard_shortcuts = ({
5456
}
5557

5658
const handle_key_up = (event: KeyboardEvent) => {
57-
if (event.key == 'Alt') set_is_alt_pressed(false)
59+
set_is_alt_pressed(
60+
event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey
61+
)
5862
}
5963

6064
const handle_blur = () => {

‎packages/ui/src/components/editor/panel/prompts/PromptField/hooks/use-keyboard-shortcuts.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const use_keyboard_shortcuts = (
1212

1313
useEffect(() => {
1414
const handle_key_down = (e: KeyboardEvent) => {
15-
if (e.key == 'Alt') set_is_alt_pressed(true)
15+
set_is_alt_pressed(e.altKey && !e.shiftKey && !e.ctrlKey && !e.metaKey)
1616

1717
if (
1818
params.on_toggle_invocation_dropdown &&
@@ -82,7 +82,7 @@ export const use_keyboard_shortcuts = (
8282
}
8383
}
8484
const handle_key_up = (e: KeyboardEvent) => {
85-
if (e.key == 'Alt') set_is_alt_pressed(false)
85+
set_is_alt_pressed(e.altKey && !e.shiftKey && !e.ctrlKey && !e.metaKey)
8686
}
8787
const handle_blur = () => {
8888
set_is_alt_pressed(false)

0 commit comments

Comments
 (0)