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(sql): keep EOF cursor on trailing statement

t8y2288cc0687ab3
diff --git a/apps/desktop/src/lib/__tests__/sql/sqlStatementRanges.spec.ts b/apps/desktop/src/lib/__tests__/sql/sqlStatementRanges.spec.ts
index db67954da1..4e3b195966 100644
--- a/apps/desktop/src/lib/__tests__/sql/sqlStatementRanges.spec.ts
+++ b/apps/desktop/src/lib/__tests__/sql/sqlStatementRanges.spec.ts
@@ -1101,6 +1101,12 @@ describe("buildExecutionCandidates", () => {
expect(candidateSummaries(candidates)).toEqual(["cursor:select 1", "all:select 1;\n\nselect 2;"]);
});
+ it("uses the final soft statement when the cursor follows trailing EOF whitespace", () => {
+ const sql = "SELECT 1\nSELECT 2 ";
+ const candidates = buildExecutionCandidates(sql, sql.length);
+ expect(candidateSummaries(candidates)).toEqual(["cursor:SELECT 2", "all:SELECT 1\nSELECT 2"]);
+ });
+
it("dedupes when the cursor statement equals the full document", () => {
const sql = "SELECT 1;";
const candidates = buildExecutionCandidates(sql, indexOf(sql, "1"));
diff --git a/apps/desktop/src/lib/sql/sqlStatementRanges.ts b/apps/desktop/src/lib/sql/sqlStatementRanges.ts
index 385fc5727b..47f2e2623f 100644
--- a/apps/desktop/src/lib/sql/sqlStatementRanges.ts
+++ b/apps/desktop/src/lib/sql/sqlStatementRanges.ts
@@ -585,8 +585,10 @@ export function statementRangeAtCursor(sql: string, cursorPos: number, databaseT
return rangeForCursorInSoftRanges(sql, softRanges, pos) ?? rangeFor(statement, sql);
}
- if (pos > statement.to && (!next || pos < next.hitFrom) && isCursorOnStatementLine(sql, pos, statement)) {
- return rangeForCursorInSoftRanges(sql, softRanges, pos) ?? rangeFor(statement, sql);
+ if (pos > statement.to && (!next || pos < next.hitFrom)) {
+ const softRange = rangeForCursorInSoftRanges(sql, softRanges, pos);
+ if (softRange) return softRange;
+ if (isCursorOnStatementLine(sql, pos, statement)) return rangeFor(statement, sql);
}
}