fix(grid): preserve data tab scroll and search across switches

This commit is contained in:
onenewcode authored and GitHub committed 2026-09-09 12:01:49 +08:00
1 parent ed29ef9eed
commit 451e50b2fb
11 files changed
+652 -15

No files matched your search

@@ -306,6 +306,7 @@ import { useDataGridAutoRefresh } from "@/composables/useDataGridAutoRefresh";
import { useDataGridAsyncSurface } from "@/composables/useDataGridAsyncSurface";
import { createDataGridFilterConditionCache, useDataGridFilterBuilder, type DataGridStructuredFilterRule } from "@/composables/useDataGridFilterBuilder";
import { cloneDataGridStructuredFilterRules, loadDataGridStructuredFilterState, saveDataGridStructuredFilterState, type DataGridCachedServerColumnFilter, type DataGridStructuredFilterCacheState } from "@/lib/dataGrid/dataGridFilterBuilderPersistence";
import { createDataGridSearchScopeKey } from "@/lib/dataGrid/dataGridSearchStatePersistence";
import { useSqlHighlighter } from "@/composables/useSqlHighlighter";
import { useCellDetailEditor, type UseCellDetailEditorReturn } from "@/composables/useCellDetailEditor";
import { useDataGridCellDetailEdit } from "@/composables/useDataGridCellDetailEdit";
@@ -992,6 +993,10 @@ const dataGridSearch = useDataGridSearch({
rows: () => displayItems.value,
getCellSearchText: (row, columnIndex) => (row.data[columnIndex] === null ? "" : rowLowerTextCache.get(row.data, columnIndex)),
onNavigate: () => nextTick(scrollToCurrentMatch),
// Same key as useDataGridEditor below: table data tabs use the tab id, query
// results use resultGridInstanceKey so a re-execute starts with a clean search.
persistenceKey: () => props.pendingStateKey ?? props.cacheKey,
persistenceScopeKey: () => createDataGridSearchScopeKey(props.result.columns),
});
const {
searchText,
@@ -1006,6 +1011,12 @@ const {
currentMatch: currentSearchMatch,
} = dataGridSearch;
// Registered ahead of useDataGridEditor's own onMounted so a restored query
// resolves the row set — "filter" search mode shrinks sortedRows — before
// applyScrollPosition measures the content height. Deliberately does not focus the
// search input: the user is returning to the grid, not to the search box.
onMounted(() => dataGridSearch.restorePersistedState());
const orderByInput = ref(props.initialOrderByInput ?? "");
const whereFilterInput = ref(props.initialWhereInput ?? "");
const conditionInputRevision = ref(0);
@@ -1533,9 +1533,7 @@ function openMongoTreeData(node: TreeNode) {
return;
}
if (node.type !== "mongo-collection") return;
const existing = queryStore.tabs.find(
(tab) => tab.mode === "mongo" && tab.connectionId === node.connectionId && tab.database === node.database && tab.tableMeta?.tableName === node.label,
);
const existing = queryStore.tabs.find((tab) => tab.mode === "mongo" && tab.connectionId === node.connectionId && tab.database === node.database && tab.tableMeta?.tableName === node.label);
if (existing) {
queryStore.switchTab(existing.id);
return;