Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 6ce5278a52 fix(editor): indent the line after Complete Current Statement like the statement
Completing `String a = "123"` added the semicolon but put the caret on
a continuation-indented line, because the new line's indent was
computed before the semicolon was there. It is now computed with the
statement finished.
2026-11-21 22:14:57 +08:00
2 змінених файлів з 20 додано та 1 видалено

No files matched your search

+9
Переглянути файл
@@ -18,6 +18,7 @@ import { toggleCaret } from "./multiCaret";
import { restructuredtextLanguage } from "./restructuredtext";
import { commentBlock, enterInLineComment, lineCommentStyle } from "./comments";
import { languages } from "@codemirror/language-data";
import { java } from "@codemirror/lang-java";
/** Brace languages in miniature: one unit deeper after a line ending in `{`. */
const javascript = () =>
@@ -314,6 +315,14 @@ describe("fallback indentation for GDScript", () => {
});
});
describe("complete current statement", () => {
it("indents the line after an added semicolon like the statement, not as its continuation", () => {
const v = make('class A {\n void f() {\n String a = "1"|\n g();\n }\n}\n', java());
completeStatement("java")(v);
expect(show(v)).toBe('class A {\n void f() {\n String a = "1";\n |\n g();\n }\n}\n');
});
});
describe("fallback indentation boundaries", () => {
const fallback = (id: string, lineComment = "#") =>
commentTokens({
+11 -1
Переглянути файл
@@ -20,6 +20,7 @@ import {
getIndentUnit,
indentString,
getIndentation,
ensureSyntaxTree,
} from "@codemirror/language";
import {
copyLineDown,
@@ -633,7 +634,16 @@ export function completeStatementSpec(state: EditorState, language: string): Tra
text.endsWith(":") ||
(KEYWORD_BLOCK_LANGS.has(language) && KEYWORD_HEAD.test(text) && !/^\s*module\b.*\bwhere$/.test(text));
const nextIndent = baseIndent + (opensBlock ? unit : "");
const indentHere = getIndentation(state, line.to);
// Indent the new line as the finished statement's next line: without the `;` the line is
// still an unfinished statement and gets a continuation indent.
let finished = state;
let lineEnd = line.to;
if (insert) {
finished = state.update({ changes: { from: line.from + text.length, insert } }).state;
lineEnd += insert.length;
ensureSyntaxTree(finished, lineEnd, 50);
}
const indentHere = getIndentation(finished, lineEnd);
const newline = br + (indentHere !== null && !opensBlock ? indentString(state, indentHere) : nextIndent);
const changes: ChangeSpec[] = [];
if (insert) changes.push({ from: line.from + text.length, insert });