fix(structure): focus search shortcut in table structure editor

This commit is contained in:
zipg authored and GitHub committed 2026-09-10 17:44:19 +08:00
1 parent e7ea2e92f2
commit dcc0b20a34
4 files changed
+35 -7

No files matched your search

@@ -278,7 +278,7 @@ const columnInfoError = ref<string | undefined>(undefined);
const dataGridRef = ref<DataGridHandle>(); const dataGridRef = ref<DataGridHandle>();
const queryEditorRef = ref<InstanceType<typeof QueryEditor>>(); const queryEditorRef = ref<InstanceType<typeof QueryEditor>>();
const elasticsearchJsonResponsePanelRef = ref<ElasticsearchJsonResponsePanelHandle>(); const elasticsearchJsonResponsePanelRef = ref<ElasticsearchJsonResponsePanelHandle>();
const tableStructureEditorRef = ref<{ applyChanges: () => Promise<boolean> }>(); const tableStructureEditorRef = ref<{ applyChanges: () => Promise<boolean>; focusSearch: () => boolean }>();
const standaloneResultToolbarRef = ref<HTMLElement | null>(null); const standaloneResultToolbarRef = ref<HTMLElement | null>(null);
const standaloneResultToolbarWidth = ref(0); const standaloneResultToolbarWidth = ref(0);
const standaloneResultToolbarViewportWidth = ref(0); const standaloneResultToolbarViewportWidth = ref(0);
@@ -917,6 +917,7 @@ function focusSearch(): boolean {
if (props.activeTab.mode === "consul") return consulWorkspaceRef.value?.focusSearch() ?? false; if (props.activeTab.mode === "consul") return consulWorkspaceRef.value?.focusSearch() ?? false;
if (props.activeTab.mode === "databases") return databaseBrowserRef.value?.focusSearch() ?? false; if (props.activeTab.mode === "databases") return databaseBrowserRef.value?.focusSearch() ?? false;
if (props.activeTab.mode === "objects") return objectBrowserRef.value?.focusSearch() ?? false; if (props.activeTab.mode === "objects") return objectBrowserRef.value?.focusSearch() ?? false;
if (props.activeTab.mode === "structure") return tableStructureEditorRef.value?.focusSearch() ?? false;
if (props.activeTab.mode === "query") { if (props.activeTab.mode === "query") {
// The shared result surface (resultOnly) owns the grid, not the editor; // The shared result surface (resultOnly) owns the grid, not the editor;
// route its search to the DataGrid instead of the missing QueryEditor. // route its search to the DataGrid instead of the missing QueryEditor.
@@ -30,6 +30,11 @@ describe("SQL editor workspace single-group tracer bullet", () => {
expect(contentAreaSource).toContain("resultOnly?: boolean"); expect(contentAreaSource).toContain("resultOnly?: boolean");
}); });
it("routes structure-tab search to the table editor instead of the sidebar", () => {
expect(contentAreaSource).toContain('if (props.activeTab.mode === "structure") return tableStructureEditorRef.value?.focusSearch() ?? false;');
expect(contentAreaSource).toContain("focusSearch: () => boolean");
});
it("keeps AppTabBar as the global special-page bar while regular tabs move to groups", () => { it("keeps AppTabBar as the global special-page bar while regular tabs move to groups", () => {
const tabBarSource = readFileSync(new URL("../AppTabBar.vue", import.meta.url), "utf8"); const tabBarSource = readFileSync(new URL("../AppTabBar.vue", import.meta.url), "utf8");
expect(tabBarSource).not.toContain("hideRegularTabs"); expect(tabBarSource).not.toContain("hideRegularTabs");
@@ -3025,6 +3025,22 @@ function focusIndexSearch() {
}); });
} }
function focusSearch(): boolean {
if (activeTab.value === "columns") {
focusColumnSearch();
return true;
}
if (activeTab.value === "indexes") {
focusIndexSearch();
return true;
}
if (activeTab.value === "ddl") {
ddlSearchPanelRef.value?.openSearch();
return true;
}
return false;
}
function scrollToIndexSearchMatch(direction: 1 | -1 = 1) { function scrollToIndexSearchMatch(direction: 1 | -1 = 1) {
const query = indexSearchText.value.trim(); const query = indexSearchText.value.trim();
if (!query) { if (!query) {
@@ -3653,7 +3669,7 @@ async function applyChanges() {
} }
} }
defineExpose({ applyChanges }); defineExpose({ applyChanges, focusSearch });
function addItemForActiveTab(): boolean { function addItemForActiveTab(): boolean {
if (activeTab.value === "columns" && canAddColumn.value) { if (activeTab.value === "columns" && canAddColumn.value) {
@@ -3719,10 +3735,10 @@ function onStructureEditorKeydown(event: KeyboardEvent) {
return; return;
} }
if (isPlainModShortcut(event, "f")) { if (isPlainModShortcut(event, "f")) {
event.preventDefault(); if (focusSearch()) {
event.stopPropagation(); event.preventDefault();
if (activeTab.value === "columns") focusColumnSearch(); event.stopPropagation();
else if (activeTab.value === "ddl") ddlSearchPanelRef.value?.openSearch(); }
return; return;
} }
if (isPlainModShortcut(event, "s")) { if (isPlainModShortcut(event, "s")) {
@@ -7,11 +7,17 @@ describe("TableStructureEditor DDL search wiring", () => {
it("uses a CodeMirror editor and the shared search panel", () => { it("uses a CodeMirror editor and the shared search panel", () => {
expect(source).toContain('import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";'); expect(source).toContain('import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";');
expect(source).toContain('key: "Mod-f"'); expect(source).toContain('key: "Mod-f"');
expect(source).toContain('else if (activeTab.value === "ddl") ddlSearchPanelRef.value?.openSearch();'); expect(source).toMatch(/if \(activeTab\.value === "ddl"\) \{\s*ddlSearchPanelRef\.value\?\.openSearch\(\);\s*return true;/);
expect(source).not.toContain("ddlPreRef"); expect(source).not.toContain("ddlPreRef");
expect(source).not.toContain("onDdlKeydown"); expect(source).not.toContain("onDdlKeydown");
}); });
it("routes the global search command to the active searchable structure tab", () => {
expect(source).toMatch(/function focusSearch\(\): boolean \{[\s\S]*activeTab\.value === "columns"[\s\S]*focusColumnSearch\(\);[\s\S]*activeTab\.value === "indexes"[\s\S]*focusIndexSearch\(\);[\s\S]*activeTab\.value === "ddl"[\s\S]*ddlSearchPanelRef\.value\?\.openSearch\(\)/);
expect(source).toContain("defineExpose({ applyChanges, focusSearch });");
expect(source).toMatch(/if \(isPlainModShortcut\(event, "f"\)\) \{\s*if \(focusSearch\(\)\)/);
});
it("keeps the DDL editable only where an executable script makes sense", () => { it("keeps the DDL editable only where an executable script makes sense", () => {
// Editable for an existing table with loaded DDL; the create-table flow has // Editable for an existing table with loaded DDL; the create-table flow has
// no DDL tab and an empty baseline only renders a placeholder string, which // no DDL tab and an empty baseline only renders a placeholder string, which