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 queryEditorRef = ref<InstanceType<typeof QueryEditor>>();
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 standaloneResultToolbarWidth = 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 === "databases") return databaseBrowserRef.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") {
// The shared result surface (resultOnly) owns the grid, not the editor;
// 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");
});
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", () => {
const tabBarSource = readFileSync(new URL("../AppTabBar.vue", import.meta.url), "utf8");
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) {
const query = indexSearchText.value.trim();
if (!query) {
@@ -3653,7 +3669,7 @@ async function applyChanges() {
}
}
defineExpose({ applyChanges });
defineExpose({ applyChanges, focusSearch });
function addItemForActiveTab(): boolean {
if (activeTab.value === "columns" && canAddColumn.value) {
@@ -3719,10 +3735,10 @@ function onStructureEditorKeydown(event: KeyboardEvent) {
return;
}
if (isPlainModShortcut(event, "f")) {
event.preventDefault();
event.stopPropagation();
if (activeTab.value === "columns") focusColumnSearch();
else if (activeTab.value === "ddl") ddlSearchPanelRef.value?.openSearch();
if (focusSearch()) {
event.preventDefault();
event.stopPropagation();
}
return;
}
if (isPlainModShortcut(event, "s")) {
@@ -7,11 +7,17 @@ describe("TableStructureEditor DDL search wiring", () => {
it("uses a CodeMirror editor and the shared search panel", () => {
expect(source).toContain('import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";');
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("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", () => {
// 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