fix(sql): keep Ctrl+Enter on current statement at trailing whitespace
This commit is contained in:
1 parent
c32f92a902
commit
b437c470e1
4 files changed
+177
-4
No files matched your search
@@ -62,8 +62,9 @@ export function executableStatementRangeAtCursor(cache: ExecutableStatementRange
|
||||
}
|
||||
|
||||
const next = cache.ranges[index + 1];
|
||||
if (pos > range.to && (!next || pos < next.from) && cursorBelongsToTrailingStatementDelimiter(cache.doc, range.to, pos)) {
|
||||
return range;
|
||||
if (pos > range.to && (!next || pos < next.from)) {
|
||||
if (cursorBelongsToTrailingStatementDelimiter(cache.doc, range.to, pos)) return range;
|
||||
if (isCursorOnRangeEndLine(cache.doc, pos, range.to)) return range;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,3 +82,8 @@ function isCursorOnLeadingBlockComment(lineText: string, lineOffset: number): bo
|
||||
|
||||
return lineOffset <= commentEnd + 2;
|
||||
}
|
||||
|
||||
function isCursorOnRangeEndLine(doc: Text, pos: number, rangeTo: number): boolean {
|
||||
const line = doc.lineAt(pos);
|
||||
return rangeTo >= line.from && rangeTo <= line.to;
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user