feat(ui): route Ctrl+F search by focused surface

This commit is contained in:
zipg authored and GitHub committed 2026-09-15 23:20:05 +08:00
1 parent 4c80d16e26
commit 3c8ae159fb
23 files changed
+233 -56

No files matched your search

@@ -110,8 +110,8 @@ function collapseAllTreeNodes() {
connectionTreeRef.value?.collapseAllTreeNodes();
}
function focusSearch(): boolean {
return connectionTreeRef.value?.focusSearch() ?? false;
function focusSearch(target: Element | null = null): boolean {
return connectionTreeRef.value?.focusSearch(target) ?? false;
}
function locateTabInSidebar(tab: QueryTab) {
@@ -197,7 +197,7 @@ defineExpose({ focusSearch, locateTabInSidebar });
</script>
<template>
<div class="app-sidebar-panel h-full shrink-0 relative select-none" :class="classicLayout ? '' : 'rounded-md border border-border/80 bg-background'" :style="{ width: sidebarWidth + 'px' }" @keydown="onSidebarKeydown">
<div data-app-sidebar class="app-sidebar-panel h-full shrink-0 relative select-none" :class="classicLayout ? '' : 'rounded-md border border-border/80 bg-background'" :style="{ width: sidebarWidth + 'px' }" @keydown="onSidebarKeydown">
<div class="h-full flex flex-col overflow-hidden">
<div class="app-sidebar-toolbar flex items-center gap-px px-3 text-xs font-medium text-muted-foreground border-b bg-muted/20" :class="classicLayout ? 'h-9' : 'h-10'">
<span v-if="showConnectionMultiSelectToolbar" class="flex min-w-0 self-stretch items-center" data-tauri-drag-region>
@@ -170,7 +170,6 @@ import type { DataGridSortMode } from "@/lib/dataGrid/dataGridSort";
import { isDataGridToolbarCompact, type DataGridReloadIntent } from "@/lib/dataGrid/dataGridToolbar";
import { useTabScroll } from "@/composables/useTabScroll";
import { useToolbarOverflow } from "@/composables/useToolbarOverflow";
import ToolbarOverflowMenu from "@/components/ui/ToolbarOverflowMenu.vue";
import { formatElapsedSeconds } from "@/lib/common/elapsedTime";
import { copyToClipboard } from "@/lib/common/clipboard";
import type { CustomSaveHandler } from "@/composables/useDataGridEditor";
@@ -183,7 +182,7 @@ import { connectionIsEffectivelyReadOnly } from "@/lib/database/readOnlyWriteAcc
type DataGridHandle = DataGridColumnLayoutHandle & {
onToolbarRefresh: () => Promise<void> | void;
focusSearch: () => boolean;
focusSearch: (target?: Element | null) => boolean;
openGoToColumn: () => boolean;
openCellDetailSearch: () => boolean;
nullColumnsHidden: boolean;
@@ -206,7 +205,7 @@ type DataGridHandle = DataGridColumnLayoutHandle & {
};
type SearchableBrowserHandle = {
focusSearch: () => boolean;
focusSearch: (target?: Element | null) => boolean;
refresh?: () => boolean;
insertCommand?: (command: string) => Promise<boolean>;
executeCommand?: (command: string) => Promise<boolean>;
@@ -304,8 +303,6 @@ const dataGridViewOptionsOpen = ref(false);
const dataToolbarRef = ref<HTMLElement | null>(null);
const { tier: dataToolbarTier } = useToolbarOverflow(dataToolbarRef, [() => props.activeTab.id, () => !!props.activeTab.result]);
const dataToolbarCompact = computed(() => dataToolbarTier.value >= 1);
const showDataToolbarOverflow = computed(() => dataToolbarTier.value >= 2);
const showDataTableInfoButton = computed(() => dataToolbarTier.value < 2);
const showDataColumnsChip = computed(() => dataToolbarTier.value < 2);
const dataGridRenderMode = computed(() => settingsStore.editorSettings.dataGridRenderMode);
const dataGridSearchMode = computed(() => settingsStore.editorSettings.dataGridSearchMode);
@@ -953,7 +950,7 @@ function onHandleCloseColumnPanel() {
columnInfoError.value = undefined;
}
function focusSearch(): boolean {
function focusSearch(target: Element | null = null): boolean {
if (elasticsearchJsonResponsePanelRef.value?.focusSearch()) return true;
if (props.activeTab.mode === "mongo") return documentBrowserRef.value?.focusSearch() ?? false;
if (props.activeTab.mode === "redis") return redisKeyBrowserRef.value?.focusSearch() ?? false;
@@ -961,15 +958,15 @@ function focusSearch(): boolean {
if (props.activeTab.mode === "zookeeper") return zookeeperKeyBrowserRef.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 === "objects") return objectBrowserRef.value?.focusSearch() ?? false;
if (props.activeTab.mode === "objects") return objectBrowserRef.value?.focusSearch(target) ?? 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.
if (props.resultOnly) return dataGridRef.value?.focusSearch() ?? false;
if (props.resultOnly) return dataGridRef.value?.focusSearch(target) ?? false;
return queryEditorRef.value?.openSearch() ?? false;
}
return dataGridRef.value?.focusSearch() ?? false;
return dataGridRef.value?.focusSearch(target) ?? false;
}
function openGoToColumn(): boolean {
@@ -2174,14 +2171,7 @@ defineExpose({
<span v-if="showDataColumnsChip && activeDataTabTableMeta" class="inline-flex shrink-0 items-center rounded border border-border bg-muted/30 px-2 py-0.5 font-medium text-muted-foreground tabular-nums"> {{ activeDataTabTableMeta.columns.length }} {{ t("tree.columns") }} </span>
<span class="ml-auto" />
<DataGridColumnLayoutPopover v-if="activeTab.result?.columns.length" :grid="dataGridRef" trigger-class="px-1.5" />
<Button
v-if="showDataTableInfoButton && activeTab.result && activeDataTabTableMeta && activeTab.connectionId"
variant="ghost"
size="sm"
class="h-5 text-xs px-1.5 shrink-0"
:class="{ 'bg-accent': dataGridRef?.showDdl }"
:title="dataToolbarCompact ? t('grid.tableInfo') : undefined"
@click="dataGridRef?.toggleDdl()"
<Button v-if="activeTab.result && activeDataTabTableMeta && activeTab.connectionId" variant="ghost" size="sm" class="h-5 text-xs px-1.5 shrink-0" :class="{ 'bg-accent': dataGridRef?.showDdl }" :title="dataToolbarCompact ? t('grid.tableInfo') : undefined" @click="dataGridRef?.toggleDdl()"
><TableProperties class="h-3.5 w-3.5" /><span v-if="!dataToolbarCompact">{{ t("grid.tableInfo") }}</span></Button
>
<DropdownMenu v-if="activeTab.result && activeDataTabTableMeta && activeTab.connectionId">
@@ -2426,12 +2416,6 @@ defineExpose({
/>
</PopoverContent>
</Popover>
<ToolbarOverflowMenu v-if="showDataToolbarOverflow" :label="t('toolbar.moreActions')">
<DropdownMenuItem v-if="activeTab.result && activeDataTabTableMeta && activeTab.connectionId" @select="dataGridRef?.toggleDdl()">
<TableProperties class="h-3.5 w-3.5" />
{{ t("grid.tableInfo") }}
</DropdownMenuItem>
</ToolbarOverflowMenu>
</div>
<DataGrid
v-if="activeTab.result"
@@ -70,7 +70,7 @@ const surfaceBindings = computed(() => ({ ...surfaceProps.value, ...contentEmits
const activeSurfaceRef = ref<QueryEditorSurfaceHandle | null>(null);
defineExpose({
focusSearch: () => activeSurfaceRef.value?.focusSearch() ?? false,
focusSearch: (target: Element | null = null) => activeSurfaceRef.value?.focusSearch(target) ?? false,
openGoToColumn: () => activeSurfaceRef.value?.openGoToColumn() ?? false,
refreshData: () => activeSurfaceRef.value?.refreshData() ?? false,
toggleResultsPane: () => activeSurfaceRef.value?.toggleResultsPane() ?? false,
@@ -22,7 +22,7 @@ const bindings = computed(() => ({ ...surfaceProps.value, ...contentEmits }));
const contentAreaRef = ref<InstanceType<typeof ContentArea> | null>(null);
defineExpose<QueryEditorSurfaceHandle>({
focusSearch: () => contentAreaRef.value?.focusSearch() ?? false,
focusSearch: (target: Element | null = null) => contentAreaRef.value?.focusSearch(target) ?? false,
openGoToColumn: () => contentAreaRef.value?.openGoToColumn() ?? false,
refreshData: () => contentAreaRef.value?.refreshData() ?? false,
toggleResultsPane: () => contentAreaRef.value?.toggleResultsPane() ?? false,
@@ -27,7 +27,7 @@ const bindings = computed(() => ({ ...surfaceProps.value, ...contentEmits }));
const contentAreaRef = ref<InstanceType<typeof ContentArea> | null>(null);
defineExpose<QueryResultSurfaceHandle>({
focusSearch: () => contentAreaRef.value?.focusSearch() ?? false,
focusSearch: (target: Element | null = null) => contentAreaRef.value?.focusSearch(target) ?? false,
refreshData: () => contentAreaRef.value?.refreshData() ?? false,
toggleResultsPane: () => contentAreaRef.value?.toggleResultsPane() ?? false,
handleModRTarget: (target: Element) => contentAreaRef.value?.handleModRTarget(target) ?? false,
@@ -66,10 +66,10 @@ defineExpose({
// A data-mode cell-detail dialog is portaled to body too but belongs to
// the group's grid — indistinguishable in the DOM, hence the gate.
if (element?.closest("[data-shared-result-surface]") || (showSharedResult.value && element?.closest("[data-cell-detail-editor-root]"))) {
return resultSurfaceRef.value?.focusSearch() ?? false;
return resultSurfaceRef.value?.focusSearch(element) ?? false;
}
const group = groupForElement(element) ?? activeEditorGroup();
return group?.focusSearch() ?? false;
return group?.focusSearch(element) ?? false;
},
openGoToColumn: () => activeEditorGroup()?.openGoToColumn() ?? false,
refreshData: (target: Element | null = null) => {
@@ -1199,7 +1199,7 @@ function showDropInside(targetId: string) {
<div class="border-b shrink-0 px-2 py-1">
<div class="relative">
<Search class="absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-muted-foreground" />
<input v-model="searchText" autocapitalize="off" autocorrect="off" spellcheck="false" class="w-full h-6 pl-7 pr-6 text-[13px] rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring" :placeholder="t('grid.search')" />
<input data-sql-library-search v-model="searchText" autocapitalize="off" autocorrect="off" spellcheck="false" class="w-full h-6 pl-7 pr-6 text-[13px] rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring" :placeholder="t('grid.search')" />
<button v-if="searchText" type="button" class="absolute right-1.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground" @click="searchText = ''">
<X class="h-3 w-3" />
</button>
@@ -0,0 +1,12 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const contentAreaSource = readFileSync(new URL("../ContentArea.vue", import.meta.url), "utf8");
describe("ContentArea data toolbar", () => {
it("keeps table properties in the primary toolbar at every overflow tier", () => {
expect(contentAreaSource).toContain('v-if="activeTab.result && activeDataTabTableMeta && activeTab.connectionId"');
expect(contentAreaSource).not.toContain("showDataTableInfoButton");
expect(contentAreaSource).not.toContain("ToolbarOverflowMenu");
});
});