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): preselect first order by suggestion

二丫讲梵7e683635dfec
diff --git a/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts
index 40045dfb42..0345aca7ea 100644
--- a/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts
+++ b/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts
@@ -293,7 +293,7 @@ describe("DataGridConditionEditor quote completion", () => {
expect(input.selectionEnd).toBe(26);
});
- it("starts without an active suggestion and selects the first item on ArrowDown", async () => {
+ it("starts with the first suggestion selected and moves to the second item on ArrowDown", async () => {
const { value, input } = mountEditor("orderBy", "", { columns: ["name", "namespace"] });
input.focus();
input.value = "na";
@@ -301,7 +301,7 @@ describe("DataGridConditionEditor quote completion", () => {
input.dispatchEvent(new Event("input", { bubbles: true }));
await vi.waitFor(() => expect(document.querySelectorAll('[role="option"]')).toHaveLength(2));
- expect(document.querySelector('[role="option"][aria-selected="true"]')).toBeNull();
+ expect(document.querySelector('[role="option"][aria-selected="true"]')?.textContent).toContain("name");
expect(value.value).toBe("na");
input.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true, cancelable: true }));
@@ -310,7 +310,7 @@ describe("DataGridConditionEditor quote completion", () => {
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }));
await nextTick();
- expect(value.value).toBe("name");
+ expect(value.value).toBe("namespace");
});
it("selects the first WHERE field suggestion with Enter", async () => {
@@ -337,16 +337,17 @@ describe("DataGridConditionEditor quote completion", () => {
input.dispatchEvent(new Event("input", { bubbles: true }));
await vi.waitFor(() => expect(document.querySelectorAll('[role="option"]')).toHaveLength(2));
+ expect(document.querySelector('[role="option"][aria-selected="true"]')?.textContent).toContain("name");
const firstOption = document.querySelector('[role="option"]') as HTMLElement;
firstOption.dispatchEvent(new MouseEvent("mouseenter", { bubbles: true, cancelable: true }));
await nextTick();
- expect(document.querySelector('[role="option"][aria-selected="true"]')).toBeNull();
+ expect(document.querySelector('[role="option"][aria-selected="true"]')?.textContent).toContain("name");
expect(firstOption.className).not.toContain("bg-gray-200");
- expect(firstOption.className).not.toContain("bg-accent");
+ expect(firstOption.className).toContain("bg-accent");
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }));
await nextTick();
- expect(value.value).toBe("na");
+ expect(value.value).toBe("name");
const secondEditor = mountEditor("orderBy", "", { columns: ["name", "namespace"] });
secondEditor.input.focus();
diff --git a/apps/desktop/src/composables/__tests__/useDataGridConditionEditor.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridConditionEditor.spec.ts
index f08057f888..17ca56cf74 100644
--- a/apps/desktop/src/composables/__tests__/useDataGridConditionEditor.spec.ts
+++ b/apps/desktop/src/composables/__tests__/useDataGridConditionEditor.spec.ts
@@ -210,7 +210,9 @@ describe("useDataGridConditionEditor", () => {
selectionEnd.value = 2;
await nextTick();
await vi.waitFor(() => expect(editor.suggestions.value).toHaveLength(2));
- editor.navigate(1);
+ // The first ORDER BY suggestion is already selected; moving up keeps the
+ // first item selected while still exercising keyboard navigation.
+ editor.navigate(-1);
expect(editor.handleKeydown(keyboardEvent("Enter"))).toBe("accept");
expect(value.value).toBe("name");
expect(editor.suggestions.value).toEqual([]);
@@ -569,31 +571,32 @@ describe("useDataGridConditionEditor", () => {
expect(aborted).toHaveBeenCalledOnce();
});
- it("maps Enter, Tab, arrows, and Escape without applying stale selections", async () => {
+ it("preselects the first ORDER BY column while preserving keyboard navigation", async () => {
const value = ref("");
const editor = useDataGridConditionEditor({ kind: "orderBy", value, columns: ["name", "namespace"], historyScope: {} });
value.value = "na";
await nextTick();
await vi.waitFor(() => expect(editor.suggestions.value).toHaveLength(2));
- expect(editor.highlightedIndex.value).toBe(-1);
+ expect(editor.highlightedIndex.value).toBe(0);
const initialEnter = keyboardEvent("Enter");
- expect(editor.handleKeydown(initialEnter)).toBe("apply");
+ expect(editor.handleKeydown(initialEnter)).toBe("accept");
expect(initialEnter.preventDefault).toHaveBeenCalledOnce();
- expect(value.value).toBe("na");
+ expect(value.value).toBe("name");
expect(editor.suggestions.value).toEqual([]);
value.value = "nam";
await nextTick();
await vi.waitFor(() => expect(editor.suggestions.value).toHaveLength(2));
+ expect(editor.highlightedIndex.value).toBe(0);
const down = keyboardEvent("ArrowDown");
expect(editor.handleKeydown(down)).toBe("navigate");
expect(down.preventDefault).toHaveBeenCalledOnce();
- expect(editor.highlightedIndex.value).toBe(0);
+ expect(editor.highlightedIndex.value).toBe(1);
const navigatedEnter = keyboardEvent("Enter");
expect(editor.handleKeydown(navigatedEnter)).toBe("accept");
- expect(value.value).toBe("name");
+ expect(value.value).toBe("namespace");
const tabValue = ref("");
const tabEditor = useDataGridConditionEditor({ kind: "orderBy", value: tabValue, columns: ["name"], historyScope: {} });
diff --git a/apps/desktop/src/composables/useDataGridConditionEditor.ts b/apps/desktop/src/composables/useDataGridConditionEditor.ts
index c9dad01912..3dfc4b9d74 100644
--- a/apps/desktop/src/composables/useDataGridConditionEditor.ts
+++ b/apps/desktop/src/composables/useDataGridConditionEditor.ts
@@ -478,9 +478,10 @@ export function useDataGridConditionEditor(options: UseDataGridConditionEditorOp
const providerValues = values ? [...new Set(values)] : undefined;
suggestions.value = providerValues ? (providerValues.some((value) => value.toLowerCase() === target.token.toLowerCase()) ? [] : providerValues.slice(0, limit).map((suggestion) => ({ value: suggestion, kind: "column" }))) : defaultSuggestions(target).slice(0, limit);
replacementRange.value = { from: target.from, to: target.to };
- // WHERE 条件开头默认选中首个列名,支持直接回车补全(issue #7155)。
- // 算术表达式、函数参数和关键字建议不默认选中,避免回车应用时改写条件(issue #10595)。
- highlightedIndex.value = options.kind === "where" && (role === "field" || role === "after_not") && shouldPreselectWhereColumn(target) && suggestions.value[0]?.kind === "column" ? 0 : -1;
+ // WHERE 条件开头和 ORDER BY 排序列位置默认选中首个列名,支持直接回车补全(issue #7155)。
+ // 算术表达式、函数参数、排序方向和关键字建议不默认选中,避免回车应用时改写条件(issue #10595)。
+ const shouldPreselectColumn = suggestions.value[0]?.kind === "column" && (options.kind === "where" ? (role === "field" || role === "after_not") && shouldPreselectWhereColumn(target) : role === "field");
+ highlightedIndex.value = shouldPreselectColumn ? 0 : -1;
} catch (error) {
if (!controller.signal.aborted && requestId === suggestionRequestId) {
suggestions.value = [];