mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-17 00:09:00 +00:00
The indent guide in the caret's column, within the block the caret line belongs to, takes the selected indent guide colour, and guides sit slightly left of their column so a caret there is to the right of the line. With the caret at a brace of a multi-line block, that block's guide takes the matched-brace colour. A double-click that puts the caret next to { or } (also past the end of a line ending in {) selects the block, both braces included; a double-click on a word still selects the word.
Co-authored-by: PLZY <41029728+PLZY@users.noreply.github.com>
39 lines
1.7 KiB
TypeScript
39 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { EditorState } from "@codemirror/state";
|
|
import { braceBlock, braceNextTo } from "./bracketBlockSelect";
|
|
|
|
const DOC = "int f(Object raw) {\n if (a) {\n g(b[0]);\n }\n}";
|
|
const state = EditorState.create({ doc: DOC });
|
|
|
|
describe("double-clicking a curly brace", () => {
|
|
it("selects the block from the opening brace to its match, both included (IDEA)", () => {
|
|
const open = DOC.indexOf("{");
|
|
expect(braceBlock(state, open)).toEqual({ from: open, to: DOC.length });
|
|
});
|
|
|
|
it("selects the same block from the closing brace", () => {
|
|
const inner = DOC.indexOf("{", DOC.indexOf("if"));
|
|
const close = DOC.indexOf("}");
|
|
expect(braceBlock(state, close)).toEqual({ from: inner, to: close + 1 });
|
|
});
|
|
|
|
it("takes the brace next to the caret the click gives, past the end of the line too", () => {
|
|
const open = DOC.indexOf("{");
|
|
const lineEnd = state.doc.line(1).to;
|
|
expect(braceNextTo(state, lineEnd, false)).toBe(open);
|
|
expect(braceNextTo(state, open, false)).toBe(open);
|
|
const close = DOC.lastIndexOf("}");
|
|
expect(braceNextTo(state, close, false)).toBe(close);
|
|
// On a word, or away from braces, the double-click selects the word.
|
|
expect(braceNextTo(state, open, true)).toBeNull();
|
|
expect(braceNextTo(state, DOC.indexOf("raw"), false)).toBeNull();
|
|
});
|
|
|
|
it("leaves parentheses, brackets, other characters and unmatched braces to the word selection", () => {
|
|
expect(braceBlock(state, DOC.indexOf("("))).toBeNull();
|
|
expect(braceBlock(state, DOC.indexOf("["))).toBeNull();
|
|
expect(braceBlock(state, DOC.indexOf("raw"))).toBeNull();
|
|
expect(braceBlock(EditorState.create({ doc: "f {" }), 2)).toBeNull();
|
|
});
|
|
});
|