From 68b696ead861bb416c339f624bea82ed478bb2dd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 15:38:37 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/normal.zig | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'core/normal.zig') diff --git a/core/normal.zig b/core/normal.zig index bb7824b2..89fd72f6 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -213,10 +213,13 @@ pub fn appendSearchLiteral(out: *std.ArrayList(u8), arena: std.mem.Allocator, te /// The file's parse, made on the first key that walks it after an edit and /// kept until the next: never made again for a key that changed nothing. +/// Of the file's text, as every parse is (File.fileText: the `Changes` +/// layer's lines are none of it). pub fn fileTree(p: *Pardes, f: *panes.File.State) ?*anyopaque { if (f.node_tree == null or f.node_tree_revision != f.revision) { + const text = panes.File.fileText(f, p.scratch.allocator()) catch return null; const old = f.node_tree; - f.node_tree = syntax.parseTree(f.path, f.content, if (f.node_tree_edits == f.revision) old else null); + f.node_tree = syntax.parseTree(f.path, text, if (f.node_tree_edits == f.revision) old else null); if (old) |o| syntax.freeTree(o); f.node_tree_revision = f.revision; f.node_tree_edits = f.revision; @@ -234,7 +237,9 @@ pub fn nodeTree(e: Editor, t: *Text, text: []const u8) ?Editor.Tree { if (comptime Editor.lib) return (e.syntax orelse return null).walkTree(text); const pane = t.pane() orelse return null; const f = if (pane.file) |*file| file else return null; - return .{ .root = fileTree(e.p, f) orelse return null, .path = f.path, .history = &f.node_history, .gpa = e.gpa }; + const root = fileTree(e.p, f) orelse return null; + const parsed = panes.File.fileText(f, e.scratch) catch return null; + return .{ .root = root, .path = f.path, .history = &f.node_history, .gpa = e.gpa, .text = parsed, .file = f }; } /// `]f`/`[f` and kin (helix goto_ts_object): to the next object starting @@ -244,8 +249,8 @@ fn objectJump(e: Editor, t: *Text, text: []const u8, range: modal.Selection, obj const tree = nodeTree(e, t, text) orelse return; var last = range; for (0..count) |_| { - const s = syntax.objectNext(tree.path, tree.root, text, object, forward, modal.selectionCursor(text, last)) orelse break; - const next: modal.Selection = .{ .anchor = s.from, .head = s.to }; + const s = syntax.objectNext(tree.path, tree.root, tree.text, object, forward, tree.in(modal.selectionCursor(text, last))) orelse break; + const next: modal.Selection = .{ .anchor = tree.out(s.from, false), .head = tree.out(s.to, s.to > s.from) }; if (std.meta.eql(next, last)) break; last = next; } @@ -292,7 +297,8 @@ pub fn nodeSelect(e: Editor, t: *Text, text: []const u8, walk: modal.Normal.Node const from = @min(r.anchor, r.head); const to = @max(r.anchor, r.head); const back = r.head < r.anchor; - const n = syntax.walkNodes(tree.root, walk, from, to, modal.selectionCursor(text, r), spans[0 .. out.len - m]); + const n = syntax.walkNodes(tree.root, walk, tree.in(from), tree.in(to), tree.in(modal.selectionCursor(text, r)), spans[0 .. out.len - m]); + for (spans[0..n]) |*s| s.* = .{ .from = tree.out(s.from, false), .to = tree.out(s.to, s.to > s.from) }; if (n == 0) { out[m] = r; m += 1; -- cgit v1.3