mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-06 14:13:06 -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 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]);
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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]
|
||||
);
|
||||
|
@ -594,7 +594,7 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros, onAddT
|
||||
<PgMenuItem shortcut={queryToolPref.clear_query}
|
||||
onClick={clearQuery}>{gettext('Clear Query')}</PgMenuItem>
|
||||
<PgMenuDivider />
|
||||
<PgMenuItem shortcut={queryToolPref.format_sql}onClick={formatSQL}>{gettext('Format SQL')}</PgMenuItem>
|
||||
<PgMenuItem shortcut={queryToolPref.format_sql} onClick={formatSQL}>{gettext('Format SQL')}</PgMenuItem>
|
||||
</PgMenu>
|
||||
<PgMenu
|
||||
anchorRef={filterMenuRef}
|
||||
|
@ -16,7 +16,7 @@ import { LayoutDockerContext, LAYOUT_EVENTS } from '../../../../../../static/js/
|
||||
import ConfirmSaveContent from '../../../../../../static/js/Dialogs/ConfirmSaveContent';
|
||||
import gettext from 'sources/gettext';
|
||||
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 { usePgAdmin } from '../../../../../../static/js/BrowserComponent';
|
||||
import ConfirmPromotionContent from '../dialogs/ConfirmPromotionContent';
|
||||
@ -470,26 +470,33 @@ export default function Query({onTextSelect}) {
|
||||
()=>{
|
||||
// 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]
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user