fix(editor): keep semicolon cursor on statement
This commit is contained in:
1 parent
8be2136658
commit
ff73a1df42
3 files changed
+33
-1
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveExecutableSql } from "../sqlExecutionTarget";
|
||||
|
||||
describe("resolveExecutableSql", () => {
|
||||
it("uses selected SQL before cursor-mode resolution", () => {
|
||||
const sql = "select 1;\n\nselect 2;";
|
||||
const selectedSql = " select 2; ";
|
||||
const cursorAfterFirstSemicolon = sql.indexOf(";") + 1;
|
||||
|
||||
expect(resolveExecutableSql(sql, selectedSql, { mode: "current", cursorPos: cursorAfterFirstSemicolon })).toBe("select 2;");
|
||||
});
|
||||
});
|
||||
@@ -172,6 +172,13 @@ describe("statementRangeAtCursor", () => {
|
||||
expect(range?.sql.trim()).toBe("SELECT *\nFROM system_dept");
|
||||
});
|
||||
|
||||
it("keeps a semicolon-line-end cursor on the current multi-line statement", () => {
|
||||
const sql = "SELECT *\nFROM system_dept;";
|
||||
const gapPos = sql.indexOf(";") + 1;
|
||||
const range = statementRangeAtCursor(sql, gapPos);
|
||||
expect(range?.sql.trim()).toBe("SELECT *\nFROM system_dept");
|
||||
});
|
||||
|
||||
it("returns the next same-line statement when the cursor is inside it", () => {
|
||||
const sql = "SELECT 1; SELECT 2;";
|
||||
const pos = indexOf(sql, "SELECT 2") + 1;
|
||||
@@ -409,6 +416,13 @@ describe("buildExecutionCandidates", () => {
|
||||
expect(candidateLabels(candidates)).toEqual(["currentStatement", "allStatements"]);
|
||||
});
|
||||
|
||||
it("uses the current statement when the cursor is immediately after its semicolon before a blank line", () => {
|
||||
const sql = "select 1;\n\nselect 2;";
|
||||
const cursorAfterFirstSemicolon = sql.indexOf(";") + 1;
|
||||
const candidates = buildExecutionCandidates(sql, cursorAfterFirstSemicolon);
|
||||
expect(candidateSummaries(candidates)).toEqual(["cursor:select 1", "all:select 1;\n\nselect 2;"]);
|
||||
});
|
||||
|
||||
it("dedupes when the cursor statement equals the full document", () => {
|
||||
const sql = "SELECT 1;";
|
||||
const candidates = buildExecutionCandidates(sql, indexOf(sql, "1"));
|
||||
|
||||
Reference in new issue
Block a user