From 690c504391e07a0767df8255e288ffe39296af22 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 07:53:29 -0300 Subject: +39 -6 lib: a new line's indent comes from the parse handed in (docs/next-editor.md): in the library, edit.treeIndent reads normal.nodeTree, the caller's `Syntax`, and its `Language`'s indent query (`indents`, which addLanguage already kept and nothing read), as a file's Enter, `o` and `O` read its own tree; without a query, or without a parse, the plain indent as before (a level more after `(`, `[`, `{` or `)`), which pushed every line of a language whose lines end in a call one level further in (examples/live, the sketch's language); pardes's own panes compile the branch out; test/lib: `f(1)` and Enter with no parse, with a grammar and no indent query (both a level in) and with one (none); hxlib 538 of 658 with 0 mismatches, core-test 811 of 950, shell-test 990 of 993, hxdiff 658 with 0 mismatches, lib-test 11 of 11 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/lib/editor.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/lib') diff --git a/test/lib/editor.zig b/test/lib/editor.zig index 2784b176..22690915 100644 --- a/test/lib/editor.zig +++ b/test/lib/editor.zig @@ -214,3 +214,28 @@ test "a byte range replaced is one step to undo, the ranges following it; a drag try std.testing.expectEqual(pe.Outcome{ .refused = .text_full }, ed.replace(a, 0, 1, &ys, false)); try std.testing.expectEqualSlices(u8, std.mem.asBytes(kept), std.mem.asBytes(ed)); } + +test "a new line's indent comes from the parse handed in, where its language has an indent query; else the plain one" { + const gpa = std.testing.allocator; + pe.syntax.start(gpa); + defer pe.syntax.stop(); + var buf: [4096]u8 = undefined; + // the plain indent is a level more after `)`: what a language whose + // lines are calls does not want, and says by an indent query + for ([_]struct { ?pe.Language, []const u8 }{ + .{ null, "f(1)\n y" }, + .{ .{ .name = "mine", .ext = ".mine", .ts = tree_sitter_c() }, "f(1)\n y" }, + .{ .{ .name = "mine", .ext = ".mine", .ts = tree_sitter_c(), .indents = "(compound_statement) @indent \"}\" @outdent" }, "f(1)\ny" }, + }) |case| { + const ed = try gpa.create(Ed); + defer gpa.destroy(ed); + ed.* = .{}; + var syn: pe.Syntax = .{ .lang = case[0] }; + defer syn.forget(); + try ed.load("f(1)"); + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + for ([_]pe.Key{ .{ .cp = 'A', .text = "A" }, .{ .cp = pe.Key.enter }, .{ .cp = 'y', .text = "y" }, .{ .cp = pe.Key.escape } }) |k| _ = ed.key(arena.allocator(), &syn, k); + try std.testing.expectEqualStrings(case[1], text(ed, &buf)); + } +} -- cgit v1.3