Fix edit menu related issues of query tool codemirror

This commit is contained in:
Aditya Toshniwal
2024-02-21 15:47:58 +05:30
parent 41812c9fde
commit b5bd236387
10 changed files with 190 additions and 46 deletions

View File

@@ -70,13 +70,14 @@ const FIXED_PREF = {
'char': 'F',
},
},
jump: {
'control': false,
gotolinecol: {
'control': true,
ctrl_is_meta: true,
'shift': false,
'alt': true,
'alt': false,
'key': {
'key_code': 71,
'char': 'G',
'key_code': 76,
'char': 'L',
},
},
indent: {
@@ -599,8 +600,8 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros}) {
onClick={()=>{eventBus.fireEvent(QUERY_TOOL_EVENTS.EDITOR_FIND_REPLACE, false);}}>{gettext('Find')}</PgMenuItem>
<PgMenuItem shortcut={FIXED_PREF.replace}
onClick={()=>{eventBus.fireEvent(QUERY_TOOL_EVENTS.EDITOR_FIND_REPLACE, true);}}>{gettext('Replace')}</PgMenuItem>
<PgMenuItem shortcut={FIXED_PREF.jump}
onClick={()=>{eventBus.fireEvent(QUERY_TOOL_EVENTS.EDITOR_EXEC_CMD, 'jumpToLine');}}>{gettext('Jump')}</PgMenuItem>
<PgMenuItem shortcut={FIXED_PREF.gotolinecol}
onClick={()=>{eventBus.fireEvent(QUERY_TOOL_EVENTS.EDITOR_EXEC_CMD, 'gotoLineCol');}}>{gettext('Go to Line/Column')}</PgMenuItem>
<PgMenuDivider />
<PgMenuItem shortcut={FIXED_PREF.indent}
onClick={()=>{eventBus.fireEvent(QUERY_TOOL_EVENTS.EDITOR_EXEC_CMD, 'indentMore');}}>{gettext('Indent Selection')}</PgMenuItem>

View File

@@ -211,7 +211,21 @@ export default function Query() {
});
eventBus.registerListener(QUERY_TOOL_EVENTS.EDITOR_EXEC_CMD, (cmd='')=>{
editor.current?.execCommand(cmd);
if(cmd == 'gotoLineCol') {
editor.current?.focus();
let key = {
keyCode: 76, metaKey: false, ctrlKey: true, shiftKey: false, altKey: false,
};
if(isMac()) {
key.metaKey = true;
key.ctrlKey = false;
key.shiftKey = false;
key.altKey = false;
}
editor.current?.fireDOMEvent(new KeyboardEvent('keydown', key));
} else {
editor.current?.execCommand(cmd);
}
});
eventBus.registerListener(QUERY_TOOL_EVENTS.COPY_TO_EDITOR, (text)=>{
editor.current?.setValue(text);
@@ -327,9 +341,7 @@ export default function Query() {
}, [queryToolCtx.preferences]);
useEffect(()=>{
registerAutocomplete(editor.current, queryToolCtx.api, queryToolCtx.params.trans_id, queryToolCtx.preferences.sqleditor,
(err)=>{eventBus.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err);}
);
registerAutocomplete(editor.current, queryToolCtx.api, queryToolCtx.params.trans_id);
}, [queryToolCtx.params.trans_id]);
const cursorActivity = useCallback(_.debounce((cursor)=>{
@@ -351,7 +363,7 @@ export default function Query() {
const closePromotionWarning = (closeModal)=>{
if(editor.current.isDirty()) {
editor.current.undo();
editor.current.execCommand('undo');
closeModal?.();
}
};
@@ -400,6 +412,5 @@ export default function Query() {
onCursorActivity={cursorActivity}
onChange={change}
autocomplete={true}
keepHistory={queryToolCtx.params.is_query_tool}
/>;
}