diff --git a/web/pgadmin/static/js/components/ReactCodeMirror/index.jsx b/web/pgadmin/static/js/components/ReactCodeMirror/index.jsx index 16842c13f..0ad5380f0 100644 --- a/web/pgadmin/static/js/components/ReactCodeMirror/index.jsx +++ b/web/pgadmin/static/js/components/ReactCodeMirror/index.jsx @@ -66,25 +66,25 @@ export default function CodeMirror({className, currEditor, showCopyBtn=false, cu const [showCopy, setShowCopy] = useState(false); const finalCustomKeyMap = useMemo(()=>[{ - key: 'Mod-f', run: (_view, e) => { - e.preventDefault(); - e.stopPropagation(); + key: 'Mod-f', run: () => { setShowFind([false, false]); setShowFind([true, false]); - } + }, + preventDefault: true, + stopPropagation: true, }, { - key: 'Mod-Alt-f', run: (_view, e) => { - e.preventDefault(); - e.stopPropagation(); + key: 'Mod-Alt-f', run: () => { setShowFind([false, false]); setShowFind([true, true]); }, + preventDefault: true, + stopPropagation: true, }, { - key: 'Mod-l', run: (_view, e) => { - e.preventDefault(); - e.stopPropagation(); + key: 'Mod-l', run: () => { setShowGoto(true); }, + preventDefault: true, + stopPropagation: true, }, ...customKeyMap], [customKeyMap]); diff --git a/web/pgadmin/static/js/utils.js b/web/pgadmin/static/js/utils.js index a1b6941b0..0726fe1e7 100644 --- a/web/pgadmin/static/js/utils.js +++ b/web/pgadmin/static/js/utils.js @@ -23,11 +23,25 @@ export function parseShortcutValue(obj) { } if (obj.alt) { shortcut += 'alt+'; } if (obj.shift) { shortcut += 'shift+'; } - if (obj.control) { shortcut += 'ctrl+'; } + if (isMac() && obj.ctrl_is_meta) { shortcut += 'meta+'; } + else if (obj.control) { shortcut += 'ctrl+'; } shortcut += obj?.key.char?.toLowerCase(); return shortcut; } +export function parseKeyEventValue(e) { + let shortcut = ''; + if(!e) { + return null; + } + if (e.altKey) { shortcut += 'alt+'; } + if (e.shiftKey) { shortcut += 'shift+'; } + if (isMac() && e.metaKey) { shortcut += 'meta+'; } + else if (e.ctrlKey) { shortcut += 'ctrl+'; } + shortcut += e.key.toLowerCase(); + return shortcut; +} + export function isShortcutValue(obj) { if(!obj) return false; return [obj.alt, obj.control, obj?.key, obj?.key?.char].every((k)=>!_.isUndefined(k)); diff --git a/web/pgadmin/tools/debugger/static/js/components/DebuggerEditor.jsx b/web/pgadmin/tools/debugger/static/js/components/DebuggerEditor.jsx index f9e741eb5..fe7544d36 100644 --- a/web/pgadmin/tools/debugger/static/js/components/DebuggerEditor.jsx +++ b/web/pgadmin/tools/debugger/static/js/components/DebuggerEditor.jsx @@ -20,7 +20,7 @@ import CodeMirror from '../../../../../static/js/components/ReactCodeMirror'; import { DEBUGGER_EVENTS } from '../DebuggerConstants'; import { DebuggerContext, DebuggerEventsContext } from './DebuggerComponent'; import { usePgAdmin } from '../../../../../static/js/BrowserComponent'; -import { isShortcutValue, toCodeMirrorKey } from '../../../../../static/js/utils'; +import { isShortcutValue, parseKeyEventValue, parseShortcutValue } from '../../../../../static/js/utils'; const StyledCodeMirror = styled(CodeMirror)(()=>({ @@ -74,10 +74,15 @@ export default function DebuggerEditor({ getEditor, params }) { const shortcutOverrideKeys = useMemo( ()=>{ - return Object.values(preferences) + // omit CM internal shortcuts + const debuggerShortcuts = Object.values(preferences) .filter((p)=>isShortcutValue(p)) - .map((p)=>({ - key: toCodeMirrorKey(p), run: (_v, e)=>{ + .map((p)=>parseShortcutValue(p)); + + return [{ + any: (_v, e)=>{ + const eventStr = parseKeyEventValue(e); + if(debuggerShortcuts.includes(eventStr)) { debuggerCtx.containerRef?.current?.dispatchEvent(new KeyboardEvent('keydown', { which: e.which, keyCode: e.keyCode, @@ -86,11 +91,13 @@ export default function DebuggerEditor({ getEditor, params }) { ctrlKey: e.ctrlKey, metaKey: e.metaKey, })); + e.preventDefault(); + e.stopPropagation(); return true; - }, - preventDefault: true, - stopPropagation: true, - })); + } + return false; + }, + }]; }, [preferences] ); diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx index 60c164438..9d804380c 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx @@ -594,7 +594,7 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros, onAddT {gettext('Clear Query')} - {gettext('Format SQL')} + {gettext('Format SQL')} { // omit CM internal shortcuts const queryToolPref = _.omit(queryToolCtx.preferences.sqleditor, ['indent', 'unindent', 'comment']); - return Object.values(queryToolPref) + const queryToolShortcuts = Object.values(queryToolPref) .filter((p)=>isShortcutValue(p)) - .map((p)=>({ - key: toCodeMirrorKey(p), run: (_v, e)=>{ - queryToolCtx.mainContainerRef?.current?.dispatchEvent(new KeyboardEvent('keydown', { - which: e.which, - keyCode: e.keyCode, - altKey: e.altKey, - shiftKey: e.shiftKey, - ctrlKey: e.ctrlKey, - metaKey: e.metaKey, - })); - if(toCodeMirrorKey(p) == 'Mod-k') { + .map((p)=>parseShortcutValue(p)); + + return [{ + any: (_v, e)=>{ + const eventStr = parseKeyEventValue(e); + if(queryToolShortcuts.includes(eventStr)) { + if((isMac() && eventStr == 'meta+k') || eventStr == 'ctrl+k') { eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_FORMAT_SQL); + } else { + queryToolCtx.mainContainerRef?.current?.dispatchEvent(new KeyboardEvent('keydown', { + which: e.which, + keyCode: e.keyCode, + altKey: e.altKey, + shiftKey: e.shiftKey, + ctrlKey: e.ctrlKey, + metaKey: e.metaKey, + })); } + e.preventDefault(); + e.stopPropagation(); return true; - }, - preventDefault: true, - stopPropagation: true, - })); + } + return false; + }, + }]; }, [queryToolCtx.preferences] );