@@ -68,6 +68,21 @@ export default function CustomModelBox({
6868 instance . cm . setSize ( '100%' , '100%' )
6969 instance . cm . on ( 'change' , ( ) => Dispatcher . dispatch ( new SetCustomModel ( instance . value , false ) ) )
7070 instance . validListener = ( valid : boolean ) => setIsValid ( valid )
71+
72+ const triggerRouting = ( ) => {
73+ try {
74+ JSON . parse ( instance . value )
75+ } catch ( e ) {
76+ Dispatcher . dispatch ( new ErrorAction ( 'Custom Model ' + ( e as SyntaxError ) . toString ( ) ) )
77+ }
78+ Dispatcher . dispatch ( new SetCustomModel ( instance . value , true ) )
79+ }
80+ // Using this keyboard shortcut we can skip the custom model validation and directly request a routing
81+ // query.
82+ instance . cm . addKeyMap ( {
83+ 'Ctrl-Enter' : triggerRouting ,
84+ 'Cmd-Enter' : triggerRouting ,
85+ } )
7186 } , [ ] )
7287
7388 useEffect ( ( ) => {
@@ -78,22 +93,6 @@ export default function CustomModelBox({
7893 if ( editor . value !== customModelStr ) editor . value = customModelStr
7994 } , [ editor , encodedValues , customModelEnabled , customModelStr ] )
8095
81- const triggerRouting = useCallback (
82- ( event : React . KeyboardEvent < HTMLInputElement > ) => {
83- if ( event . ctrlKey && event . key === 'Enter' ) {
84- // Using this keyboard shortcut we can skip the custom model validation and directly request a routing
85- // query.
86- try {
87- JSON . parse ( editor . value )
88- } catch ( e ) {
89- Dispatcher . dispatch ( new ErrorAction ( 'Custom Model ' + ( e as SyntaxError ) . toString ( ) ) )
90- }
91- Dispatcher . dispatch ( new SetCustomModel ( editor . value , true ) )
92- }
93- } ,
94- [ editor , isValid ] ,
95- )
96-
9796 return (
9897 < >
9998 < div className = { styles . customModelOptionTable } >
@@ -119,7 +118,7 @@ export default function CustomModelBox({
119118 </ PlainButton >
120119 ) }
121120 </ div >
122- < div ref = { divElement } className = { styles . customModelBox } onKeyUp = { triggerRouting } />
121+ < div ref = { divElement } className = { styles . customModelBox } />
123122 < div className = { styles . customModelBoxBottomBar } >
124123 < select
125124 className = { styles . examples }
0 commit comments