Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(grid): search full cell values past display truncation

ericbyzf0d14ebfa6a1
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 70288f6080..2d4674c723 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -5409,7 +5409,15 @@ const sortedRows = computed(() => {
const rows = props.result.rows;
indices = indices.filter((sourceIndex) => {
const data = rows[sourceIndex];
- return data.some((cell, columnIndex) => cell !== null && rowLowerTextCache.get(data, columnIndex).includes(q));
+ return data.some((cell, columnIndex) => {
+ if (cell === null) return false;
+ const text = rowLowerTextCache.get(data, columnIndex);
+ if (text.includes(q)) return true;
+ // The display cache is truncated at the cell display cap, so a match
+ // past the cut would wrongly hide a row that a WHERE clause finds;
+ // re-check the full raw string value (#11956).
+ return text.endsWith("...") && typeof cell === "string" && cell.toLowerCase().includes(q);
+ });
});
}
return indices;
diff --git a/apps/desktop/src/composables/useDataGridSearch.ts b/apps/desktop/src/composables/useDataGridSearch.ts
index 41176cd23d..e4d1b2f507 100644
--- a/apps/desktop/src/composables/useDataGridSearch.ts
+++ b/apps/desktop/src/composables/useDataGridSearch.ts
@@ -34,6 +34,9 @@ export type UseDataGridSearchOptions<Row> = {
const SEARCH_TOKEN_SEPARATOR = /[\s,()><=!&|]+/;
const SEARCH_TOKEN_SUFFIX = /([^\s,()><=!&|]+)$/;
const SEARCH_PAIRS: Record<string, string> = { "'": "'", '"': '"', "(": ")" };
+// limitDataGridCellDisplay appends this marker when it caps a cell's display
+// text; a search miss on such a cell can hide a match past the cut (#11956).
+const TRUNCATED_CELL_SUFFIX = "...";
export function useDataGridSearch<Row>(options: UseDataGridSearchOptions<Row>) {
const searchText = ref("");
@@ -77,7 +80,17 @@ export function useDataGridSearch<Row>(options: UseDataGridSearchOptions<Row>) {
columns.forEach((_, col) => {
if (options.isCellSearchable && !options.isCellSearchable(row, col)) return;
const text = (pattern || sensitive) && options.getCellRawSearchText ? options.getCellRawSearchText(row, col) : options.getCellSearchText(row, col);
- if (includes(text)) addMatch(displayRow, col);
+ if (includes(text)) {
+ addMatch(displayRow, col);
+ return;
+ }
+ // The cached display text may be truncated (hosts cap cell display
+ // length), so a plain miss can hide a match that sits past the cut.
+ // Re-check the full raw value of truncated cells — but not in replace
+ // mode, whose raw provider and scope stay display-driven.
+ if (!pattern && text.endsWith(TRUNCATED_CELL_SUFFIX) && options.getCellRawSearchText && includes(options.getCellRawSearchText(row, col))) {
+ addMatch(displayRow, col);
+ }
});
});
return { keys, matchSet };
diff --git a/packages/app-tests/repro-issue-11956.test.ts b/packages/app-tests/repro-issue-11956.test.ts
new file mode 100644
index 0000000000..bd75625f9d
--- /dev/null
+++ b/packages/app-tests/repro-issue-11956.test.ts
@@ -0,0 +1,77 @@
+// Regression tests for upstream issue t8y2/dbx#11956:
+// 「对查询表数据进行搜索时,数据存在但搜索不到」
+// The result-grid Ctrl+F search runs over the FORMATTED DISPLAY text of each
+// cell, which DataGrid.vue truncates with limitDataGridCellDisplay at
+// DATA_GRID_CELL_DISPLAY_MAX_LENGTH (256) characters. A search term past that
+// cut was invisible to Ctrl+F while a server-side WHERE found it.
+//
+// Fix: the match scan re-checks the full raw value of cells whose display text
+// is truncated (ends with "..."), so matches past the display cut are found.
+//
+// The wiring below mirrors DataGrid.vue's useDataGridSearch call for a plain
+// text column (DataGrid.vue:1146-1170): search text = lowercase of the
+// 256-char-truncated display value.
+import { nextTick } from "vue";
+import { test, vi } from "vitest";
+import { strict as assert } from "node:assert";
+import { useDataGridSearch } from "../../apps/desktop/src/composables/useDataGridSearch.ts";
+import { limitDataGridCellDisplay } from "../../apps/desktop/src/lib/dataGrid/cellValue.ts";
+
+async function flushSearchDebounce() {
+ await nextTick();
+ vi.runOnlyPendingTimers();
+ await nextTick();
+ await nextTick();
+}
+
+// Same shape as DataGrid.vue's getCellSearchText for a plain text column.
+const cellSearchText = (row: string[], column: number): string => limitDataGridCellDisplay(String(row[column] ?? "")).toLowerCase();
+
+function longValue(prefix: string, needle: string, totalLength: number): string {
+ const head = `${prefix}${"x".repeat(totalLength)}`.slice(0, totalLength);
+ // Place the needle just past the 256-character display cut.
+ return head.slice(0, 260) + needle + head.slice(260 + needle.length);
+}
+
+test("finds values whose match sits past the 256-char display cut", async () => {
+ vi.useFakeTimers();
+
+ const rows = [
+ [longValue("row A: ", "needle_a", 400)],
+ [longValue("row B: ", "needle_b", 400)],
+ [longValue("row C: ", "needle_c", 400)],
+ // Control: same row shape but the keyword within the first 256 chars.
+ [longValue("row D: ", "needle_d", 100)],
+ ];
+ const search = useDataGridSearch({
+ columns: ["content"],
+ rows,
+ getCellSearchText: cellSearchText,
+ getCellRawSearchText: (row, col) => String(row[col] ?? ""),
+ includeColumnMatches: false,
+ });
+
+ for (const needle of ["needle_a", "needle_b", "needle_c", "needle_d"]) {
+ search.searchText.value = needle;
+ await flushSearchDebounce();
+ assert.equal(search.matchCount.value, 1, `Ctrl+F "${needle}" should match its row; the data exists and WHERE finds it`);
+ }
+});
+
+test("does not report truncated cells whose raw value has no match", async () => {
+ vi.useFakeTimers();
+
+ // A raw value that legitimately ends with "..." but never contains the query
+ // must not become a false positive through the raw re-check.
+ const rows = [["x".repeat(300) + "..."]];
+ const search = useDataGridSearch({
+ columns: ["content"],
+ rows,
+ getCellSearchText: cellSearchText,
+ getCellRawSearchText: (row, col) => String(row[col] ?? ""),
+ includeColumnMatches: false,
+ });
+ search.searchText.value = "needle_none";
+ await flushSearchDebounce();
+ assert.equal(search.matchCount.value, 0);
+});