@@ -316,35 +316,31 @@ export default function Query({onTextSelect, setQtStatePartial}) {
316316 ) , { id :modalId } ) ;
317317 } ;
318318
319+ const createKeyObjectFromShortcut = ( pref ) => {
320+ // this function creates a key object from the shortcut preference
321+ let key = {
322+ keyCode : pref . key . key_code ,
323+ metaKey : pref . ctrl_is_meta ,
324+ ctrlKey : pref . control ,
325+ shiftKey : pref . shift ,
326+ altKey : pref . alt ,
327+ } ;
328+ if ( isMac ( ) ) {
329+ key . metaKey = true ;
330+ key . ctrlKey = false ;
331+ }
332+ return key ;
333+ } ;
334+
319335 const unregisterEditorExecCmd = eventBus . registerListener ( QUERY_TOOL_EVENTS . EDITOR_EXEC_CMD , ( cmd = '' ) => {
320336 let key = { } , gotolinecol = queryToolCtx . preferences . sqleditor . goto_line_col ,
321337 formatSql = queryToolCtx . preferences . sqleditor . format_sql ;
322338 switch ( cmd ) {
323339 case 'gotoLineCol' :
324- key = {
325- keyCode : gotolinecol . key . key_code ,
326- metaKey : gotolinecol . ctrl_is_meta ,
327- ctrlKey : gotolinecol . control ,
328- shiftKey : gotolinecol . shift ,
329- altKey : gotolinecol . alt ,
330- } ;
331- if ( isMac ( ) ) {
332- key . metaKey = true ;
333- key . ctrlKey = false ;
334- }
340+ key = createKeyObjectFromShortcut ( gotolinecol ) ;
335341 break ;
336342 case 'formatSql' :
337- key = {
338- keyCode : formatSql . key . key_code ,
339- metaKey : formatSql . ctrl_is_meta ,
340- ctrlKey : formatSql . control ,
341- shiftKey : formatSql . shift ,
342- altKey : formatSql . alt ,
343- } ;
344- if ( isMac ( ) ) {
345- key . metaKey = true ;
346- key . ctrlKey = false ;
347- }
343+ key = createKeyObjectFromShortcut ( formatSql ) ;
348344 break ;
349345 default :
350346 editor . current ?. execCommand ( cmd ) ;
@@ -359,25 +355,9 @@ export default function Query({onTextSelect, setQtStatePartial}) {
359355 let key = { } ;
360356 editor . current ?. focus ( ) ;
361357 if ( ! replace ) {
362- key = {
363- keyCode : findShortcut . key . key_code ,
364- metaKey : findShortcut . ctrl_is_meta ,
365- ctrlKey : findShortcut . control ,
366- shiftKey : findShortcut . shift ,
367- altKey : findShortcut . alt ,
368- } ;
358+ key = createKeyObjectFromShortcut ( findShortcut ) ;
369359 } else {
370- key = {
371- keyCode : replaceShortcut . key . key_code ,
372- metaKey : replaceShortcut . ctrl_is_meta ,
373- ctrlKey : replaceShortcut . control ,
374- shiftKe : replaceShortcut . shift ,
375- altKey : replaceShortcut . alt ,
376- } ;
377- }
378- if ( isMac ( ) ) {
379- key . metaKey = true ;
380- key . ctrlKey = false ;
360+ key = createKeyObjectFromShortcut ( replaceShortcut ) ;
381361 }
382362 editor . current ?. fireDOMEvent ( new KeyboardEvent ( 'keydown' , key ) ) ;
383363 } ) ;
0 commit comments