fix(shortcuts): refresh data with F5
This commit is contained in:
@@ -43,6 +43,7 @@ import {
|
||||
isExecuteSqlShortcut,
|
||||
isFocusSearchShortcut,
|
||||
isObjectSourceSaveShortcutTarget,
|
||||
isRefreshDataShortcut,
|
||||
isSaveShortcut,
|
||||
} from "@/lib/keyboardShortcuts";
|
||||
import { isPreviewTab } from "@/lib/tabPresentation";
|
||||
@@ -562,6 +563,12 @@ function handleKeydown(e: KeyboardEvent) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (isRefreshDataShortcut(e, shortcuts)) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
contentAreaRef.value?.refreshData();
|
||||
return;
|
||||
}
|
||||
if (isCloseTabShortcut(e, shortcuts)) {
|
||||
e.preventDefault();
|
||||
if (showDriverStore.value) {
|
||||
|
||||
@@ -198,7 +198,13 @@ function focusSearch(): boolean {
|
||||
return dataGridRef.value?.focusSearch() ?? false;
|
||||
}
|
||||
|
||||
defineExpose({ focusSearch });
|
||||
function refreshData(): boolean {
|
||||
if (!dataGridRef.value) return false;
|
||||
void dataGridRef.value.onToolbarRefresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
defineExpose({ focusSearch, refreshData });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1141,6 +1141,7 @@ export default {
|
||||
shortcutSaveSql: "Save SQL",
|
||||
shortcutCloseTab: "Close tab",
|
||||
shortcutFocusSearch: "Focus search",
|
||||
shortcutRefreshData: "Refresh data",
|
||||
shortcutCancelSearch: "Cancel search",
|
||||
shortcutScopeGlobal: "Global",
|
||||
shortcutScopeEditor: "SQL editor",
|
||||
|
||||
@@ -1046,6 +1046,7 @@ export default {
|
||||
shortcutSaveSql: "Guardar SQL",
|
||||
shortcutCloseTab: "Cerrar pestaña",
|
||||
shortcutFocusSearch: "Enfocar búsqueda",
|
||||
shortcutRefreshData: "Actualizar datos",
|
||||
shortcutCancelSearch: "Cancelar búsqueda",
|
||||
shortcutScopeGlobal: "Global",
|
||||
shortcutScopeEditor: "Editor SQL",
|
||||
|
||||
@@ -1118,6 +1118,7 @@ export default {
|
||||
shortcutSaveSql: "保存 SQL",
|
||||
shortcutCloseTab: "关闭标签页",
|
||||
shortcutFocusSearch: "聚焦搜索",
|
||||
shortcutRefreshData: "刷新数据",
|
||||
shortcutCancelSearch: "取消搜索",
|
||||
shortcutScopeGlobal: "全局",
|
||||
shortcutScopeEditor: "SQL 编辑器",
|
||||
|
||||
@@ -80,6 +80,10 @@ export function isFocusSearchShortcut(event: ShortcutLikeEvent, shortcuts?: Part
|
||||
return matchesShortcut(event, actionShortcut("focusSearch", shortcuts));
|
||||
}
|
||||
|
||||
export function isRefreshDataShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("refreshData", shortcuts));
|
||||
}
|
||||
|
||||
export function isSaveShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("saveSql", shortcuts));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type ShortcutActionId = "executeSql" | "saveSql" | "closeTab" | "focusSearch" | "cancelSearch";
|
||||
export type ShortcutActionId = "executeSql" | "saveSql" | "closeTab" | "focusSearch" | "refreshData" | "cancelSearch";
|
||||
|
||||
export type ShortcutScope = "global" | "editor" | "search";
|
||||
|
||||
@@ -36,6 +36,12 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
|
||||
scope: "global",
|
||||
defaultShortcut: "Mod+F",
|
||||
},
|
||||
{
|
||||
id: "refreshData",
|
||||
labelKey: "settings.shortcutRefreshData",
|
||||
scope: "global",
|
||||
defaultShortcut: "F5",
|
||||
},
|
||||
{
|
||||
id: "cancelSearch",
|
||||
labelKey: "settings.shortcutCancelSearch",
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
isExecuteSqlShortcut,
|
||||
isFocusSearchShortcut,
|
||||
isObjectSourceSaveShortcutTarget,
|
||||
isRefreshDataShortcut,
|
||||
isSaveShortcut,
|
||||
} from "../../apps/desktop/src/lib/keyboardShortcuts.ts";
|
||||
import { shortcutToCodeMirrorKey } from "../../apps/desktop/src/lib/shortcutRegistry.ts";
|
||||
@@ -67,6 +68,18 @@ test("matches Cmd+F for focusing search", () => {
|
||||
assert.equal(isFocusSearchShortcut({ key: "F", metaKey: true }), true);
|
||||
});
|
||||
|
||||
test("matches F5 for refreshing data", () => {
|
||||
assert.equal(isRefreshDataShortcut({ key: "F5" }), true);
|
||||
});
|
||||
|
||||
test("matches custom shortcut settings for refreshing data", () => {
|
||||
assert.equal(isRefreshDataShortcut({ key: "F5" }, { refreshData: "Shift+Mod+R" } as any), false);
|
||||
assert.equal(
|
||||
isRefreshDataShortcut({ key: "r", metaKey: true, shiftKey: true } as any, { refreshData: "Shift+Mod+R" } as any),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("ignores focus search shortcut while composing", () => {
|
||||
assert.equal(isFocusSearchShortcut({ key: "f", ctrlKey: true, isComposing: true }), false);
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@ test("defaults shortcut settings", () => {
|
||||
assert.equal(settings.shortcuts.executeSql, "Mod+Enter");
|
||||
assert.equal(settings.shortcuts.saveSql, "Mod+S");
|
||||
assert.equal(settings.shortcuts.focusSearch, "Mod+F");
|
||||
assert.equal(settings.shortcuts.refreshData, "F5");
|
||||
});
|
||||
|
||||
test("keeps saved shortcut overrides", () => {
|
||||
|
||||
Reference in New Issue
Block a user