Skip to content

Commit bec6f08

Browse files
committed
Use Cmd+Enter as keyboard shortcut in custom model editor for macOS
* Ctrl+Enter conflicts with macOS context menu shortcut * apparently macOS suppresses keyup if Cmd is pressed
1 parent df90f09 commit bec6f08

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

src/sidebar/CustomModelBox.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)