feat(app): add new query shortcut
This commit is contained in:
parent
ab6c73c687
commit
888d3d8890
|
|
@ -38,6 +38,7 @@ import {
|
|||
isCloseTabShortcut,
|
||||
isExecuteSqlShortcut,
|
||||
isFocusSearchShortcut,
|
||||
isNewQueryShortcut,
|
||||
isObjectSourceSaveShortcutTarget,
|
||||
isRefreshDataShortcut,
|
||||
isSaveShortcut,
|
||||
|
|
@ -587,6 +588,12 @@ function handleKeydown(e: KeyboardEvent) {
|
|||
contentAreaRef.value?.refreshData();
|
||||
return;
|
||||
}
|
||||
if (isNewQueryShortcut(e, shortcuts)) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
void newQuery();
|
||||
return;
|
||||
}
|
||||
if (isCloseTabShortcut(e, shortcuts)) {
|
||||
e.preventDefault();
|
||||
if (showDriverStore.value) {
|
||||
|
|
|
|||
|
|
@ -1198,6 +1198,7 @@ export default {
|
|||
redisScanPageSizeOption: "{count} keys",
|
||||
shortcutExecuteSql: "Execute SQL",
|
||||
shortcutSaveSql: "Save SQL",
|
||||
shortcutNewQuery: "New query",
|
||||
shortcutCloseTab: "Close tab",
|
||||
shortcutFocusSearch: "Focus search",
|
||||
shortcutRefreshData: "Refresh data",
|
||||
|
|
|
|||
|
|
@ -1097,6 +1097,7 @@ export default {
|
|||
redisScanPageSizeOption: "{count} claves",
|
||||
shortcutExecuteSql: "Ejecutar SQL",
|
||||
shortcutSaveSql: "Guardar SQL",
|
||||
shortcutNewQuery: "Nueva consulta",
|
||||
shortcutCloseTab: "Cerrar pestaña",
|
||||
shortcutFocusSearch: "Enfocar búsqueda",
|
||||
shortcutRefreshData: "Actualizar datos",
|
||||
|
|
|
|||
|
|
@ -1176,6 +1176,7 @@ export default {
|
|||
redisScanPageSizeOption: "{count} 个 Key",
|
||||
shortcutExecuteSql: "执行 SQL",
|
||||
shortcutSaveSql: "保存 SQL",
|
||||
shortcutNewQuery: "新建查询",
|
||||
shortcutCloseTab: "关闭标签页",
|
||||
shortcutFocusSearch: "聚焦搜索",
|
||||
shortcutRefreshData: "刷新数据",
|
||||
|
|
|
|||
|
|
@ -76,6 +76,10 @@ export function isCloseTabShortcut(event: ShortcutLikeEvent, shortcuts?: Partial
|
|||
return matchesShortcut(event, actionShortcut("closeTab", shortcuts));
|
||||
}
|
||||
|
||||
export function isNewQueryShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("newQuery", shortcuts));
|
||||
}
|
||||
|
||||
export function isFocusSearchShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("focusSearch", shortcuts));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,11 @@
|
|||
export type ShortcutActionId = "executeSql" | "saveSql" | "closeTab" | "focusSearch" | "refreshData" | "cancelSearch";
|
||||
export type ShortcutActionId =
|
||||
| "executeSql"
|
||||
| "saveSql"
|
||||
| "newQuery"
|
||||
| "closeTab"
|
||||
| "focusSearch"
|
||||
| "refreshData"
|
||||
| "cancelSearch";
|
||||
|
||||
export type ShortcutScope = "global" | "editor" | "search";
|
||||
|
||||
|
|
@ -24,6 +31,12 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
|
|||
scope: "editor",
|
||||
defaultShortcut: "Mod+S",
|
||||
},
|
||||
{
|
||||
id: "newQuery",
|
||||
labelKey: "settings.shortcutNewQuery",
|
||||
scope: "global",
|
||||
defaultShortcut: "Mod+T",
|
||||
},
|
||||
{
|
||||
id: "closeTab",
|
||||
labelKey: "settings.shortcutCloseTab",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
isCloseTabShortcut,
|
||||
isExecuteSqlShortcut,
|
||||
isFocusSearchShortcut,
|
||||
isNewQueryShortcut,
|
||||
isObjectSourceSaveShortcutTarget,
|
||||
isRefreshDataShortcut,
|
||||
isSaveShortcut,
|
||||
|
|
@ -44,6 +45,18 @@ test("matches Ctrl+Enter for SQL execution", () => {
|
|||
assert.equal(isExecuteSqlShortcut({ key: "Enter", ctrlKey: true }), true);
|
||||
});
|
||||
|
||||
test("matches Cmd+T for opening a new query", () => {
|
||||
assert.equal(isNewQueryShortcut({ key: "t", metaKey: true }), true);
|
||||
});
|
||||
|
||||
test("matches custom shortcut settings for opening a new query", () => {
|
||||
assert.equal(isNewQueryShortcut({ key: "t", metaKey: true }, { newQuery: "Shift+Mod+N" } as any), false);
|
||||
assert.equal(
|
||||
isNewQueryShortcut({ key: "n", ctrlKey: true, shiftKey: true } as any, { newQuery: "Shift+Mod+N" } as any),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("ignores Enter without modifier", () => {
|
||||
assert.equal(isExecuteSqlShortcut({ key: "Enter" }), false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -28,14 +28,16 @@ test("defaults shortcut settings", () => {
|
|||
|
||||
assert.equal(settings.shortcuts.executeSql, "Mod+Enter");
|
||||
assert.equal(settings.shortcuts.saveSql, "Mod+S");
|
||||
assert.equal(settings.shortcuts.newQuery, "Mod+T");
|
||||
assert.equal(settings.shortcuts.focusSearch, "Mod+F");
|
||||
assert.equal(settings.shortcuts.refreshData, "F5");
|
||||
});
|
||||
|
||||
test("keeps saved shortcut overrides", () => {
|
||||
const settings = normalizeEditorSettings({ shortcuts: { executeSql: "Shift+Mod+Enter" } as any });
|
||||
const settings = normalizeEditorSettings({ shortcuts: { executeSql: "Shift+Mod+Enter", newQuery: "Shift+Mod+N" } as any });
|
||||
|
||||
assert.equal(settings.shortcuts.executeSql, "Shift+Mod+Enter");
|
||||
assert.equal(settings.shortcuts.newQuery, "Shift+Mod+N");
|
||||
assert.equal(settings.shortcuts.saveSql, "Mod+S");
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue