@@ -16,6 +16,7 @@ import {
1616} from "lucide-react" ;
1717import React , { type FormEvent , type KeyboardEvent , useCallback , useMemo , useState } from "react" ;
1818
19+ import { keybindingFromKeyboardEvent } from "~/components/settings/KeybindingsSettings.logic" ;
1920import {
2021 keybindingValueForCommand ,
2122 decodeProjectScriptKeybindingRule ,
@@ -26,7 +27,6 @@ import {
2627 primaryProjectScript ,
2728} from "~/projectScripts" ;
2829import { shortcutLabelForCommand } from "~/keybindings" ;
29- import { isMacPlatform } from "~/lib/utils" ;
3030import {
3131 AlertDialog ,
3232 AlertDialogClose ,
@@ -96,57 +96,6 @@ interface ProjectScriptsControlProps {
9696 onDeleteScript : ( scriptId : string ) => Promise < void > | void ;
9797}
9898
99- function normalizeShortcutKeyToken ( key : string ) : string | null {
100- const normalized = key . toLowerCase ( ) ;
101- if (
102- normalized === "meta" ||
103- normalized === "control" ||
104- normalized === "ctrl" ||
105- normalized === "shift" ||
106- normalized === "alt" ||
107- normalized === "option"
108- ) {
109- return null ;
110- }
111- if ( normalized === " " ) return "space" ;
112- if ( normalized === "escape" ) return "esc" ;
113- if ( normalized === "arrowup" ) return "arrowup" ;
114- if ( normalized === "arrowdown" ) return "arrowdown" ;
115- if ( normalized === "arrowleft" ) return "arrowleft" ;
116- if ( normalized === "arrowright" ) return "arrowright" ;
117- if ( normalized . length === 1 ) return normalized ;
118- if ( normalized . startsWith ( "f" ) && normalized . length <= 3 ) return normalized ;
119- if ( normalized === "enter" || normalized === "tab" || normalized === "backspace" ) {
120- return normalized ;
121- }
122- if ( normalized === "delete" || normalized === "home" || normalized === "end" ) {
123- return normalized ;
124- }
125- if ( normalized === "pageup" || normalized === "pagedown" ) return normalized ;
126- return null ;
127- }
128-
129- function keybindingFromEvent ( event : KeyboardEvent < HTMLInputElement > ) : string | null {
130- const keyToken = normalizeShortcutKeyToken ( event . key ) ;
131- if ( ! keyToken ) return null ;
132-
133- const parts : string [ ] = [ ] ;
134- if ( isMacPlatform ( navigator . platform ) ) {
135- if ( event . metaKey ) parts . push ( "mod" ) ;
136- if ( event . ctrlKey ) parts . push ( "ctrl" ) ;
137- } else {
138- if ( event . ctrlKey ) parts . push ( "mod" ) ;
139- if ( event . metaKey ) parts . push ( "meta" ) ;
140- }
141- if ( event . altKey ) parts . push ( "alt" ) ;
142- if ( event . shiftKey ) parts . push ( "shift" ) ;
143- if ( parts . length === 0 ) {
144- return null ;
145- }
146- parts . push ( keyToken ) ;
147- return parts . join ( "+" ) ;
148- }
149-
15099export default function ProjectScriptsControl ( {
151100 scripts,
152101 keybindings,
@@ -186,7 +135,7 @@ export default function ProjectScriptsControl({
186135 setKeybinding ( "" ) ;
187136 return ;
188137 }
189- const next = keybindingFromEvent ( event ) ;
138+ const next = keybindingFromKeyboardEvent ( event , navigator . platform ) ;
190139 if ( ! next ) return ;
191140 setKeybinding ( next ) ;
192141 } ;
0 commit comments