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/Editor.zig | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'core/Editor.zig') diff --git a/core/Editor.zig b/core/Editor.zig index aaf6ab05..9e490c41 100644 --- a/core/Editor.zig +++ b/core/Editor.zig @@ -12,6 +12,7 @@ const Registers = @import("Registers.zig"); /// on this at compile time, so the library never compiles the core. pub const lib = @import("pardes_options").lib; const Pardes = if (lib) void else @import("Core.zig"); +const File = if (lib) void else @import("File.zig"); const Syntax = if (lib) @import("lib_editor.zig").Syntax else void; const modal = @import("modal.zig"); @@ -20,8 +21,30 @@ const Editor = @This(); /// A text's parse as the tree-sitter walks read it (normal.nodeTree): the /// tree, a path its grammar's queries are found by, and helix's /// object_selections, what Alt-o grew from for Alt-i to go back to, its -/// ranges in `gpa`. Dropped with the tree when the text changes. -pub const Tree = struct { root: *anyopaque, path: []const u8, history: *std.ArrayList(NodeStep), gpa: std.mem.Allocator }; +/// ranges in `gpa`. Dropped with the tree when the text changes. `text` is +/// what it parsed: a file's text (File.fileText: never the `Changes` +/// layer's lines, which are the buffer's), whose places `in` and `out` map +/// from and to the buffer's; the buffer itself with no layer shown, and +/// the library's text. +pub const Tree = struct { + root: *anyopaque, + path: []const u8, + history: *std.ArrayList(NodeStep), + gpa: std.mem.Allocator, + text: []const u8, + file: if (lib) void else *const File.State, + + /// A place in the buffer as the tree's text's (File.fileOffset). + pub fn in(tree: Tree, at: usize) usize { + return if (lib) at else File.fileOffset(tree.file, at); + } + + /// A place in the tree's text as the buffer's; `end`, a range's end + /// (File.bufferOffset). + pub fn out(tree: Tree, at: usize, end: bool) usize { + return if (lib) at else File.bufferOffset(tree.file, at, end); + } +}; pub const NodeStep = struct { ranges: []modal.Selection, primary: usize }; gpa: std.mem.Allocator, -- cgit v1.3