@@ -7,6 +7,7 @@ import { mountGraphExecutionBridge } from '@/core/executor/executor';
77import { editorApi } from './editorApi' ;
88import { useEditorStore } from './store/useEditorStore' ;
99import { useSettingsStore } from './store/useSettingsStore' ;
10+ import { isEditableTarget , useWindowKeydown } from '@/shortcuts' ;
1011
1112function Editor ( ) {
1213 const { projectId } = useParams ( ) ;
@@ -96,46 +97,33 @@ function Editor() {
9697
9798 useEffect ( ( ) => mountGraphExecutionBridge ( ) , [ ] ) ;
9899
99- useEffect ( ( ) => {
100- if ( ! projectId ) return ;
101-
102- const isEditableTarget = ( target : EventTarget | null ) => {
103- if ( ! ( target instanceof HTMLElement ) ) return false ;
104- if ( target . isContentEditable ) return true ;
105- const tagName = target . tagName . toLowerCase ( ) ;
106- return (
107- tagName === 'input' || tagName === 'textarea' || tagName === 'select'
108- ) ;
109- } ;
110-
111- const routeByDigit : Record < string , string > = {
112- '1' : `/editor/project/${ projectId } ` ,
113- '2' : `/editor/project/${ projectId } /blueprint` ,
114- '3' : `/editor/project/${ projectId } /nodegraph` ,
115- '4' : `/editor/project/${ projectId } /animation` ,
116- '5' : `/editor/project/${ projectId } /component` ,
117- '6' : `/editor/project/${ projectId } /resources` ,
118- '7' : `/editor/project/${ projectId } /test` ,
119- '8' : `/editor/project/${ projectId } /export` ,
120- '9' : `/editor/project/${ projectId } /deployment` ,
121- } ;
122-
123- const onKeyDown = ( event : globalThis . KeyboardEvent ) => {
100+ useWindowKeydown (
101+ ( event ) => {
102+ if ( ! projectId ) return ;
124103 if ( event . defaultPrevented ) return ;
125104 if ( isEditableTarget ( event . target ) ) return ;
126105 if ( ! event . altKey || event . ctrlKey || event . metaKey || event . shiftKey ) {
127106 return ;
128107 }
108+ const routeByDigit : Record < string , string > = {
109+ '1' : `/editor/project/${ projectId } ` ,
110+ '2' : `/editor/project/${ projectId } /blueprint` ,
111+ '3' : `/editor/project/${ projectId } /nodegraph` ,
112+ '4' : `/editor/project/${ projectId } /animation` ,
113+ '5' : `/editor/project/${ projectId } /component` ,
114+ '6' : `/editor/project/${ projectId } /resources` ,
115+ '7' : `/editor/project/${ projectId } /test` ,
116+ '8' : `/editor/project/${ projectId } /export` ,
117+ '9' : `/editor/project/${ projectId } /deployment` ,
118+ } ;
129119 const nextPath = routeByDigit [ event . key ] ;
130120 if ( ! nextPath ) return ;
131121 if ( location . pathname === nextPath ) return ;
132122 event . preventDefault ( ) ;
133123 navigate ( nextPath ) ;
134- } ;
135-
136- window . addEventListener ( 'keydown' , onKeyDown ) ;
137- return ( ) => window . removeEventListener ( 'keydown' , onKeyDown ) ;
138- } , [ location . pathname , navigate , projectId ] ) ;
124+ } ,
125+ { enabled : Boolean ( projectId ) }
126+ ) ;
139127
140128 return (
141129 < div className = "flex min-h-screen max-h-screen flex-row bg-[linear-gradient(120deg,var(--color-0)_20%,var(--color-1)_100%)]" >
0 commit comments