summaryrefslogtreecommitdiff
path: root/core/jj.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 15:38:37 -0300
committerGabriel Schneider <[email protected]>2026-11-23 15:40:56 -0300
commit68b696ead861bb416c339f624bea82ed478bb2dd (patch)
tree95605dee66b8f3419bf0a4715d17b3493de1492c /core/jj.zig
parent3e60c54651f10fe9233a40bc1f1fdaed141d2116 (diff)
downloadpardes-68b696ead861bb416c339f624bea82ed478bb2dd.tar.gz
pardes-68b696ead861bb416c339f624bea82ed478bb2dd.zip
changes layer: the node keys and the indent parse the FILE's text, as every other parse does (round 8 left them parsing the buffer with the layer's lines in it): `normal.fileTree` parses `File.fileText` (the buffer itself with no layer: a length test), and `Editor.Tree` carries the text it parsed and the file whose buffer the keys' places are of, `in` (a buffer place as the tree's: `File.fileOffset`) and `out` (back: `File.bufferOffset`, a range's end before the layer's lines standing there; the library's text is its own: both the identity at comptime): Alt-o and kin (`nodeSelect`: the walk asked in the file's places, its spans mapped back), `]f` and kin (`objectJump`), a tree-sitter text object (`maf` and kin, edit.zig), and `o`'s indent (`treeIndent`: the file's text, row and offset with the layer shown; unchanged with none); `File.edit` tells the kept tree of no edit with the layer's lines in the buffer or going in or out (`told`, `read_only`): it is the file's text's, parsed anew at the next key; THE FAILING TEST FIRST (core/jj.zig "the node keys and the indent read the file's text ..."): with the layer shown and hidden, the cursor on `c2();`, Alt-o once, twice and three times and `maf` give the same range of the file's text (9P's `dot`), and `o` the same new line: on the round's base the function's text object selected nothing beside the layer's lines (27..27 where hidden 0..34: the description line in the buffer broke the function's parse); with this, equal; core-test filtered on jj (Debug tui) 55/55
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/jj.zig')
-rw-r--r--core/jj.zig53
1 files changed, 53 insertions, 0 deletions
diff --git a/core/jj.zig b/core/jj.zig
index 963e4c42..78c0e857 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -3498,6 +3498,59 @@ test "the layer's lines are the pane's text, read-only: j and k go onto them, a
}
}
+test "the node keys and the indent read the file's text: Alt-o and a function's text object beside the layer's lines select what they select with the layer hidden (the layer's lines inside the node with it), and o opens a line indented as there" {
+ const gpa = testing.allocator;
+ var repo = try Lines.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 44 });
+ defer p.deinit();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const pane = try Lines.open(p, repo.file);
+ const id = p.view().active;
+ const f = &pane.file.?;
+ const alt_o: pardes.Event = .{ .key = .{ .cp = 'o', .alt = true } };
+ // What each gesture selects, in the file's offsets (9P's dot), with the
+ // cursor on `c2();`'s `c`: buffer line 4 with the layer shown, the
+ // file's line 2 hidden.
+ const Gesture = enum { node1, node2, node3, function };
+ var shown: [4]pardes.ctlfs.pane.State.Range = undefined;
+ var hidden: [4]pardes.ctlfs.pane.State.Range = undefined;
+ for ([_]bool{ true, false }) |layer| {
+ p.view().active = id;
+ if (!layer) p.update(.{ .command = "Changes" });
+ try testing.expectEqual(layer, f.read_only.len > 0);
+ const row: i32 = if (layer) 4 else 2;
+ for (std.enums.values(Gesture), 0..) |g, k| {
+ p.view().active = id;
+ Lines.at(pane, row, 4);
+ switch (g) {
+ .node1, .node2, .node3 => for (0..@intFromEnum(g) + 1) |_| p.update(alt_o),
+ .function => Lines.send(p, "maf"),
+ }
+ (if (layer) &shown else &hidden)[k] = pardes.ctlfs.pane.fileDot(pane);
+ Lines.send(p, "\x1b;");
+ }
+ }
+ errdefer for (shown, hidden) |s, h| std.debug.print("shown {d}..{d} hidden {d}..{d}\n", .{ s.q0, s.q1, h.q0, h.q1 });
+ for (shown, hidden) |s, h| try testing.expectEqual(h, s);
+ // The function, the whole file less its last newline: hidden, the text.
+ try testing.expectEqualStrings("fn f() void {\n a();\n c2();\n}", Lines.cut_text[hidden[3].q0..hidden[3].q1]);
+ // `o` on `c2();`: the line opened with the indent it gets hidden.
+ var opened: [2][]const u8 = undefined;
+ for ([_]bool{ false, true }, &opened) |layer, *o| {
+ p.view().active = id;
+ if (layer) p.update(.{ .command = "Changes" });
+ try testing.expectEqual(layer, f.read_only.len > 0);
+ Lines.at(pane, if (layer) 4 else 2, 4);
+ Lines.send(p, "ox\x1b");
+ o.* = try arena.allocator().dupe(u8, try File.fileText(f, arena.allocator()));
+ Lines.send(p, "u");
+ }
+ try testing.expectEqualStrings("fn f() void {\n a();\n c2();\n x\n}\n", opened[0]);
+ try testing.expectEqualStrings(opened[0], opened[1]);
+}
+
test "THE FILE'S TEXT: with the layer's lines in the buffer, every reader of the file reads what it reads with them out, byte for byte: a Save, a Save to another name, Edit's w, body over 9P, the dirty check, a reread from the disk, a Get, jj's lines asked again, the context declarations, the colours of the file's lines, the language server's text and the place it is asked at" {
const gpa = testing.allocator;
var repo = try Lines.repo() orelse return error.SkipZigTest;