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(completion): stop appending space before statement terminators

zipg257e023120f6
diff --git a/apps/desktop/src/lib/__tests__/editor/sqlCompletionInsertion.spec.ts b/apps/desktop/src/lib/__tests__/editor/sqlCompletionInsertion.spec.ts
index 0ff0a751a8..36f30f02e8 100644
--- a/apps/desktop/src/lib/__tests__/editor/sqlCompletionInsertion.spec.ts
+++ b/apps/desktop/src/lib/__tests__/editor/sqlCompletionInsertion.spec.ts
@@ -17,6 +17,13 @@ describe("SQL completion insertion", () => {
expect(appendSqlCompletionSpace("orders", { enabled: true, itemType: "table", nextCharacter: "," })).toBe("orders");
});
+ it("keeps the space when a statement terminator follows the cursor", () => {
+ // Completing `BETWEEN` before an existing `;` must not glue the two together,
+ // otherwise the user cannot keep typing the operand without fixing the text.
+ expect(appendSqlCompletionSpace("BETWEEN", { enabled: true, itemType: "keyword", nextCharacter: ";" })).toBe("BETWEEN ");
+ expect(appendSqlCompletionSpace("SALARY", { enabled: true, itemType: "column", nextCharacter: ";" })).toBe("SALARY ");
+ });
+
it("honors the setting and leaves snippet-like completions unchanged", () => {
expect(appendSqlCompletionSpace("SELECT", { enabled: false, itemType: "keyword" })).toBe("SELECT");
expect(appendSqlCompletionSpace("CASE ${value}", { enabled: true, itemType: "snippet" })).toBe("CASE ${value}");
diff --git a/apps/desktop/src/lib/editor/sqlCompletionInsertion.ts b/apps/desktop/src/lib/editor/sqlCompletionInsertion.ts
index a5bd2d0114..79acd48d9c 100644
--- a/apps/desktop/src/lib/editor/sqlCompletionInsertion.ts
+++ b/apps/desktop/src/lib/editor/sqlCompletionInsertion.ts
@@ -1,6 +1,9 @@
export type SqlCompletionItemType = "keyword" | "table" | "column" | "snippet" | "function" | "schema" | "variable" | "property" | "text";
-const COMPLETION_SPACE_BLOCKING_CHARACTERS = new Set([",", ";", ":", ")", "]", "}", "'", '"']);
+// `;` is deliberately absent: a statement terminator is never glued to the token
+// in front of it, and accepting `BETWEEN` before an existing `;` used to insert
+// `BETWEEN;`, leaving the user no way to keep typing the operand.
+const COMPLETION_SPACE_BLOCKING_CHARACTERS = new Set([",", ":", ")", "]", "}", "'", '"']);
export function appendSqlCompletionSpace(insertText: string, options: { enabled: boolean; itemType: SqlCompletionItemType; nextCharacter?: string }): string {
if (!options.enabled || options.itemType === "property" || options.itemType === "text" || options.itemType === "schema" || options.itemType === "variable" || options.itemType === "snippet" || options.itemType === "function") return insertText;
diff --git a/docs/screenshots/issue-9528-after.png b/docs/screenshots/issue-9528-after.png
new file mode 100644
index 0000000000..2e8c233ad3
Binary files /dev/null and b/docs/screenshots/issue-9528-after.png differ
diff --git a/docs/screenshots/issue-9528-before.png b/docs/screenshots/issue-9528-before.png
new file mode 100644
index 0000000000..a46fa8d7b0
Binary files /dev/null and b/docs/screenshots/issue-9528-before.png differ