@@ -31,7 +31,7 @@ export default function QueryWindow({
3131 tabKey,
3232} : QueryWindowProps ) {
3333 const editorRef = useRef < ReactCodeMirrorRef > ( null ) ;
34- const { setTabData } = useWindowTab ( ) ;
34+ const { selectedTab , setTabData } = useWindowTab ( ) ;
3535 const { runner } = useSqlExecute ( ) ;
3636 const { showErrorDialog } = useDialog ( ) ;
3737 const [ result , setResult ] = useState < SqlStatementResult [ ] > ( [ ] ) ;
@@ -133,8 +133,24 @@ export default function QueryWindow({
133133 ) ;
134134
135135 const onRun = useCallback ( ( ) => {
136- executeSql ( code ) ;
137- } , [ executeSql , code ] ) ;
136+ if ( editorRef . current ) {
137+ const sqlCode = editorRef . current . view ?. state . doc . toString ( ) || '' ;
138+ executeSql ( sqlCode ) ;
139+ }
140+ } , [ executeSql , editorRef ] ) ;
141+
142+ useEffect ( ( ) => {
143+ if ( selectedTab === tabKey ) {
144+ const onKeyBinding = ( e : KeyboardEvent ) => {
145+ if ( e . key === 'F9' ) {
146+ onRun ( ) ;
147+ }
148+ } ;
149+
150+ document . addEventListener ( 'keydown' , onKeyBinding ) ;
151+ return ( ) => document . removeEventListener ( 'keydown' , onKeyBinding ) ;
152+ }
153+ } , [ onRun , selectedTab , tabKey ] ) ;
138154
139155 useEffect ( ( ) => {
140156 if ( initialRun && initialSql ) {
@@ -155,7 +171,7 @@ export default function QueryWindow({
155171 < Toolbar >
156172 < Toolbar . Item
157173 icon = { < FontAwesomeIcon icon = { faPlay } /> }
158- text = "Run"
174+ text = "Run (F9) "
159175 onClick = { onRun }
160176 />
161177 </ Toolbar >
0 commit comments