fix(sql): keep Ctrl+Enter on current statement at trailing whitespace

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-08-07 02:56:26 +08:00
1 parent c32f92a902
commit b437c470e1
4 files changed
+177 -4

No files matched your search

@@ -597,7 +597,7 @@ export function statementRangeAtCursor(sql: string, cursorPos: number, databaseT
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);
if (isCursorOnRangeEndLine(sql, pos, statement)) return rangeFor(statement, sql);
}
}
@@ -639,7 +639,7 @@ function rangeForCursorInSoftRanges(sql: string, ranges: RawStatement[], pos: nu
}
const next = ranges[index + 1];
if (pos > range.to && (!next || pos < next.hitFrom) && isCursorOnStatementLine(sql, pos, range)) {
if (pos > range.to && (!next || pos < next.hitFrom) && isCursorOnRangeEndLine(sql, pos, range)) {
return rangeFor(range, sql);
}
}
@@ -1992,6 +1992,13 @@ function isCursorOnStatementLine(sql: string, pos: number, statement: Pick<RawSt
return statement.from >= lineStart && statement.from <= lineEnd;
}
function isCursorOnRangeEndLine(sql: string, pos: number, range: Pick<RawStatement, "to">): boolean {
const lineStart = sql.lastIndexOf("\n", pos - 1) + 1;
let lineEnd = sql.indexOf("\n", pos);
if (lineEnd === -1) lineEnd = sql.length;
return range.to >= lineStart && range.to <= lineEnd;
}
/**
* Returns the full document as a range, or `null` when it is empty/whitespace.
*/