mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-08 15:13:10 -06:00
Fixed an issue where query tool shortcuts for find/replace are not working. #7555
This commit is contained in:
parent
b5c8692f34
commit
e03d65d547
@ -66,25 +66,25 @@ export default function CodeMirror({className, currEditor, showCopyBtn=false, cu
|
|||||||
const [showCopy, setShowCopy] = useState(false);
|
const [showCopy, setShowCopy] = useState(false);
|
||||||
|
|
||||||
const finalCustomKeyMap = useMemo(()=>[{
|
const finalCustomKeyMap = useMemo(()=>[{
|
||||||
key: 'Mod-f', run: (_view, e) => {
|
key: 'Mod-f', run: () => {
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
setShowFind([false, false]);
|
setShowFind([false, false]);
|
||||||
setShowFind([true, false]);
|
setShowFind([true, false]);
|
||||||
}
|
},
|
||||||
|
preventDefault: true,
|
||||||
|
stopPropagation: true,
|
||||||
}, {
|
}, {
|
||||||
key: 'Mod-Alt-f', run: (_view, e) => {
|
key: 'Mod-Alt-f', run: () => {
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
setShowFind([false, false]);
|
setShowFind([false, false]);
|
||||||
setShowFind([true, true]);
|
setShowFind([true, true]);
|
||||||
},
|
},
|
||||||
|
preventDefault: true,
|
||||||
|
stopPropagation: true,
|
||||||
}, {
|
}, {
|
||||||
key: 'Mod-l', run: (_view, e) => {
|
key: 'Mod-l', run: () => {
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
setShowGoto(true);
|
setShowGoto(true);
|
||||||
},
|
},
|
||||||
|
preventDefault: true,
|
||||||
|
stopPropagation: true,
|
||||||
},
|
},
|
||||||
...customKeyMap], [customKeyMap]);
|
...customKeyMap], [customKeyMap]);
|
||||||
|
|
||||||
|
@ -23,11 +23,25 @@ export function parseShortcutValue(obj) {
|
|||||||
}
|
}
|
||||||
if (obj.alt) { shortcut += 'alt+'; }
|
if (obj.alt) { shortcut += 'alt+'; }
|
||||||
if (obj.shift) { shortcut += 'shift+'; }
|
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();
|
shortcut += obj?.key.char?.toLowerCase();
|
||||||
return shortcut;
|
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) {
|
export function isShortcutValue(obj) {
|
||||||
if(!obj) return false;
|
if(!obj) return false;
|
||||||
return [obj.alt, obj.control, obj?.key, obj?.key?.char].every((k)=>!_.isUndefined(k));
|
return [obj.alt, obj.control, obj?.key, obj?.key?.char].every((k)=>!_.isUndefined(k));
|
||||||
|
@ -20,7 +20,7 @@ import CodeMirror from '../../../../../static/js/components/ReactCodeMirror';
|
|||||||
import { DEBUGGER_EVENTS } from '../DebuggerConstants';
|
import { DEBUGGER_EVENTS } from '../DebuggerConstants';
|
||||||
import { DebuggerContext, DebuggerEventsContext } from './DebuggerComponent';
|
import { DebuggerContext, DebuggerEventsContext } from './DebuggerComponent';
|
||||||
import { usePgAdmin } from '../../../../../static/js/BrowserComponent';
|
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)(()=>({
|
const StyledCodeMirror = styled(CodeMirror)(()=>({
|
||||||
@ -74,10 +74,15 @@ export default function DebuggerEditor({ getEditor, params }) {
|
|||||||
|
|
||||||
const shortcutOverrideKeys = useMemo(
|
const shortcutOverrideKeys = useMemo(
|
||||||
()=>{
|
()=>{
|
||||||
return Object.values(preferences)
|
// omit CM internal shortcuts
|
||||||
|
const debuggerShortcuts = Object.values(preferences)
|
||||||
.filter((p)=>isShortcutValue(p))
|
.filter((p)=>isShortcutValue(p))
|
||||||
.map((p)=>({
|
.map((p)=>parseShortcutValue(p));
|
||||||
key: toCodeMirrorKey(p), run: (_v, e)=>{
|
|
||||||
|
return [{
|
||||||
|
any: (_v, e)=>{
|
||||||
|
const eventStr = parseKeyEventValue(e);
|
||||||
|
if(debuggerShortcuts.includes(eventStr)) {
|
||||||
debuggerCtx.containerRef?.current?.dispatchEvent(new KeyboardEvent('keydown', {
|
debuggerCtx.containerRef?.current?.dispatchEvent(new KeyboardEvent('keydown', {
|
||||||
which: e.which,
|
which: e.which,
|
||||||
keyCode: e.keyCode,
|
keyCode: e.keyCode,
|
||||||
@ -86,11 +91,13 @@ export default function DebuggerEditor({ getEditor, params }) {
|
|||||||
ctrlKey: e.ctrlKey,
|
ctrlKey: e.ctrlKey,
|
||||||
metaKey: e.metaKey,
|
metaKey: e.metaKey,
|
||||||
}));
|
}));
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
preventDefault: true,
|
}];
|
||||||
stopPropagation: true,
|
|
||||||
}));
|
|
||||||
},
|
},
|
||||||
[preferences]
|
[preferences]
|
||||||
);
|
);
|
||||||
|
@ -16,7 +16,7 @@ import { LayoutDockerContext, LAYOUT_EVENTS } from '../../../../../../static/js/
|
|||||||
import ConfirmSaveContent from '../../../../../../static/js/Dialogs/ConfirmSaveContent';
|
import ConfirmSaveContent from '../../../../../../static/js/Dialogs/ConfirmSaveContent';
|
||||||
import gettext from 'sources/gettext';
|
import gettext from 'sources/gettext';
|
||||||
import { isMac } from '../../../../../../static/js/keyboard_shortcuts';
|
import { isMac } from '../../../../../../static/js/keyboard_shortcuts';
|
||||||
import { checkTrojanSource, isShortcutValue, toCodeMirrorKey } from '../../../../../../static/js/utils';
|
import { checkTrojanSource, isShortcutValue, parseKeyEventValue, parseShortcutValue } from '../../../../../../static/js/utils';
|
||||||
import { parseApiError } from '../../../../../../static/js/api_instance';
|
import { parseApiError } from '../../../../../../static/js/api_instance';
|
||||||
import { usePgAdmin } from '../../../../../../static/js/BrowserComponent';
|
import { usePgAdmin } from '../../../../../../static/js/BrowserComponent';
|
||||||
import ConfirmPromotionContent from '../dialogs/ConfirmPromotionContent';
|
import ConfirmPromotionContent from '../dialogs/ConfirmPromotionContent';
|
||||||
@ -470,10 +470,17 @@ export default function Query({onTextSelect}) {
|
|||||||
()=>{
|
()=>{
|
||||||
// omit CM internal shortcuts
|
// omit CM internal shortcuts
|
||||||
const queryToolPref = _.omit(queryToolCtx.preferences.sqleditor, ['indent', 'unindent', 'comment']);
|
const queryToolPref = _.omit(queryToolCtx.preferences.sqleditor, ['indent', 'unindent', 'comment']);
|
||||||
return Object.values(queryToolPref)
|
const queryToolShortcuts = Object.values(queryToolPref)
|
||||||
.filter((p)=>isShortcutValue(p))
|
.filter((p)=>isShortcutValue(p))
|
||||||
.map((p)=>({
|
.map((p)=>parseShortcutValue(p));
|
||||||
key: toCodeMirrorKey(p), run: (_v, e)=>{
|
|
||||||
|
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', {
|
queryToolCtx.mainContainerRef?.current?.dispatchEvent(new KeyboardEvent('keydown', {
|
||||||
which: e.which,
|
which: e.which,
|
||||||
keyCode: e.keyCode,
|
keyCode: e.keyCode,
|
||||||
@ -482,14 +489,14 @@ export default function Query({onTextSelect}) {
|
|||||||
ctrlKey: e.ctrlKey,
|
ctrlKey: e.ctrlKey,
|
||||||
metaKey: e.metaKey,
|
metaKey: e.metaKey,
|
||||||
}));
|
}));
|
||||||
if(toCodeMirrorKey(p) == 'Mod-k') {
|
|
||||||
eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_FORMAT_SQL);
|
|
||||||
}
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
preventDefault: true,
|
}];
|
||||||
stopPropagation: true,
|
|
||||||
}));
|
|
||||||
},
|
},
|
||||||
[queryToolCtx.preferences]
|
[queryToolCtx.preferences]
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user