querymx / querym

Querym is free, open-source and cross-platform MySQL and PostgreSQL GUI client.
https://querym.net/
GNU General Public License v3.0
94 stars 28 forks source link

Hotkey proposal #88

Closed rin-yato closed 1 year ago

rin-yato commented 1 year ago

I think F9 isnt the best hotkey to execute sql. Since many people use keyboard that cant easily type the F9 key. Maybe command/ctrl + enter is a good hotkey?

invisal commented 1 year ago

Thanks for suggestion. The Command/Ctrl + Enter has bee suggested before. Maybe the best is to let people bind their own key? We can extend this functionality. If you want to extend this, I can provide some guideline how to achieve it.

rin-yato commented 1 year ago

You may provide the guideline, I will help out with what I can.

invisal commented 1 year ago

Got it. Let me do some design to give you some idea how to achieve it

invisal commented 1 year ago

We can start by doing the following

const [keybinding] = useState(() => ({
  'RUN': { mac: 'Command+Enter', win: 'Ctrl+Enter' },
  'RUN_SELECTION': { mac: 'Command+Shift+Enter', win: 'Ctrl+Shift+Enter' }
}))

const getKeybinding = useCallback((key: string) => {
  return keybinding[key];
}, [keybinding])

const matchKeybinding = useCallback((e: EventKeySomething, key: string) => {
  // returning true if the key event is matched
}, [keybinding])

<KeybindingProvider value={{getKeybinding }}>
   { /*... */}
</KeybindingProvider>

I believe other place can do as following:

const {getKeybinding, matchKeybinding} = useKeybinding();

const onKeypress = useCallback(e => {
    if (matchKeybinding(e, 'RUN')) {
       // do something
    }
}, [getKeybinding])