From b1fb4242c0ab52767df1b8e155edcf2692f37873 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 18:00:35 -0300 Subject: scroll: a view's top is a line and a row within that line's own wrapped rows, and a scroll moves it by rows (P62, round 3, on the layer's new model where the `Changes` layer's lines are lines of the buffer): a wheel's notch, the glide, PageDown/PageUp, zj/zk, Ctrl-d/u, zt/zz/zb and the margin (`scroll_off` now ROWS) go a row at a time through a line wrapped over many rows and through a long description line of the layer, where the base jumped all of a wrapped line's rows at once (the user, 2026-11-23: "the scroll view jumps around near deleted lines on the diff view"; one-row deleted lines were cured by the layer's second step, a wrapped one was not): TESTS FIRST: core/jj.zig "a view scrolls by rows through a line wrapped over 12 rows and a change's description wrapped over several (a line of the layer): ..." (a notch is one row down the whole text and back, the notches the text's rows exactly; PageDown/PageUp a page of rows; zj/zk one; a held j and k keep the cursor's row `scroll_off` rows inside the body) failing on the base at notch 21 (line 20's 12 rows crossed at once), and "a client wheels its session's view a row a notch into a change's description wrapped over several rows ..., agreeing at every notch; a client joined over that view loads its row"; kept from round 1: core/replica.zig's join over a view scrolled into a wrapped line (with a rollback and a dump) and the explorer of a view's rows (30 seeds), dev/gui's glide a row a notch; THE CHANGE, taken from pardes-row-scroll (`xrxmqlnw`) and -2 (`xxzmwnvq`) without their ghost-row "blocks" (a block is now just a line's own rows): `File.State.scroll_row` and `views.PaneView.scroll_row` in the generic walk (digested, dumped, copied; a dump of 34 loads at its lines' first rows), the wire 35; core/File.zig `Top`, `rowIn`/`rowWalked` (a line's rows as fillBody wraps them, `guideOf` shared), `rowOf`, `lineRows`, `top`/`setTop`, `walkRows`/`walkKnown`, `rowsTo`, `rowsOf` (off the map where it holds the line), `mapFresh`, `scrollRows`, `shownRows` (the geometry laid out first), `show` (a cursor's or a result's row inside the band, the line's rows whole when they fit), `textRowLine`, fillBody's skip to the top's row walked once a geometry (`Pane.top_skip`, derived), the geometry's key with `scroll_row` and stored as what the map was made from; the one-row fact `State.widest` (`Widest`, an upper bound kept by the index's own vector passes `countLines`/`fillLines`) so a view whose lines are each one row walks nothing (`oneRow`: line arithmetic, checked against the walk in Debug); `fitEnd` a vector of printable ASCII at a time; the callers in rows: panes.zig `scrollBy(tab, delta)` and `ensureCursorVisible` (a file's through `File.show`), the wheel and the rail and the edge scroll (mouse.zig), Ctrl-d/u (normal.zig `halfPageMove`), zt/zz/zb, Ctrl-f/b and PgUp/PgDn (Text.zig `scrollViewMove`), Look's reveal and centring, Places' `goTo`/`restore`, Query's `showCurrent`/`caretTo`, the frames' `Region.row` and the glide (dev/glide.zig, the window's `topOf`); test/perf.zig's checks by (line, row) and its seek at a line's first row; Debug in the workspace: core-test 963/1129 (166 skipped), shell-test 1172/1175 (3 skipped) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/File.zig | 503 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 464 insertions(+), 39 deletions(-) (limited to 'core/File.zig') diff --git a/core/File.zig b/core/File.zig index b2df6c0f..86861792 100644 --- a/core/File.zig +++ b/core/File.zig @@ -98,7 +98,7 @@ pub const State = struct { /// from the text whenever it is wanted. // Syntax caches must not load through the dump loader's core allocator. pub const replica = .{ - .derived = .{ "cap", "line_starts", "line_cap", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_tree_edits", "node_history", "tables" }, + .derived = .{ "cap", "line_starts", "line_cap", "widest", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_tree_edits", "node_history", "tables" }, // Big texts, dumped and sent by their hash (core/walk.zig). The // text is written in place by `replace`, but never while a join // sends it (memory.zig `pin`): then an edit puts a new buffer in @@ -160,11 +160,18 @@ pub const State = struct { /// A directory pane's entries (Dir.zig), its output `.dir`. listing: ?panes.Dir.State = null, mini: ?Mini.State = null, + /// The view's top: the line its first row is of, and that row of the + /// line's wrapped rows (`Top`): each view's own (views.zig), digested, + /// dumped. scroll: usize = 0, + scroll_row: u32 = 0, /// `line_starts[i]` is line i's byte offset. Empty means not built yet. line_starts: []usize = &.{}, /// The room `line_starts` has, as `cap` is `content`'s. line_cap: usize = 0, + /// The widest any line is, found with the index and kept with it + /// (`Widest`): what tells a view whose rows are its lines (`oneRow`). + widest: Widest = .{}, /// One tree_sitter_gpa-owned syntax.Syn byte per highlighted source byte. highlights: []u8 = &.{}, location_rows: []locations.Row = &.{}, @@ -605,6 +612,16 @@ pub fn renderedLineDisplayCol(tab: u16, pane: *const Pane, row: i32, line_text: pub fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize { var end = start; var used: usize = 0; + // A vector of printable ASCII at a time, a cell a byte, while the width + // is past it and the byte after it is ASCII too: what the loop below + // takes a byte at a time (it leaves the ASCII byte a non-ASCII one + // follows to the grapheme walk). Every row walk is this loop. + while (used + lanes < width and end + lanes < text.len and text[end + lanes] < 0x80) { + const v: Lanes = text[end..][0..lanes].*; + if (@reduce(.Or, v -% @as(Lanes, @splat(0x20)) >= @as(Lanes, @splat(0x5f)))) break; + used += lanes; + end += lanes; + } while (used < width and end < text.len) { const b = text[end]; if (b < 0x20 or b >= 0x7f) break; @@ -629,20 +646,91 @@ pub fn lineIndex(gpa: std.mem.Allocator, f: *State) ![]const usize { if (f.line_starts.len > 0) return f.line_starts; // Exact allocation: deinitPane frees `line_starts` itself, so the stored // slice must span the complete allocation rather than spare capacity. - const starts = try gpa.alloc(usize, lineCount(f.content)); + const found = countLines(f.content); + const starts = try gpa.alloc(usize, found.newlines + 1); starts[0] = 0; - var i: usize = 1; - var off: usize = 0; - while (std.mem.indexOfScalarPos(u8, f.content, off, '\n')) |nl| { - off = nl + 1; - starts[i] = off; - i += 1; - } + f.widest = .{ .bytes = fillLines(f.content, 0, starts[1..]), .tabbed = found.tabbed }; f.line_starts = starts; f.line_cap = 0; return starts; } +/// The widest a text's lines are, at most: the most bytes between two +/// newlines, and whether a tab is among them. A tab is `tab` cells, any +/// other byte at most one (graphemeDisplayWidth), so a line is never +/// wider than its bytes, times the tab width where a tab may be. Made +/// with the line index and kept by its edits, only ever made wider: an +/// edit taking the widest line away leaves it so (`oneRow` then walks, +/// and finds the same rows). +pub const Widest = struct { + bytes: usize = 0, + tabbed: bool = false, + + fn cells(w: Widest, tab: u16) usize { + return if (w.tabbed) w.bytes *| @max(tab, 1) else w.bytes; + } +}; + +const lanes = std.simd.suggestVectorLength(u8) orelse 16; +const Lanes = @Vector(lanes, u8); + +/// The newlines in `bytes` and whether a tab is among them: a lane's own +/// sum a vector, added up every 255 (std.mem.count's popcount of a mask is +/// a dozen instructions a vector on a baseline x86-64). +fn countLines(bytes: []const u8) struct { newlines: usize, tabbed: bool } { + const one: Lanes = @splat(1); + const zero: Lanes = @splat(0); + var newlines: usize = 0; + var tabs = zero; + var i: usize = 0; + while (bytes.len - i >= lanes) { + var sums = zero; + for (0..@min((bytes.len - i) / lanes, 255)) |_| { + const v: Lanes = bytes[i..][0..lanes].*; + sums += @select(u8, v == @as(Lanes, @splat('\n')), one, zero); + tabs |= @select(u8, v == @as(Lanes, @splat('\t')), one, zero); + i += lanes; + } + newlines += @reduce(.Add, @as(@Vector(lanes, u16), sums)); + } + var tabbed = @reduce(.Or, tabs) != 0; + for (bytes[i..]) |b| { + newlines += @intFromBool(b == '\n'); + tabbed = tabbed or b == '\t'; + } + return .{ .newlines = newlines, .tabbed = tabbed }; +} + +/// The start after each newline of `bytes` (its byte `off` past it) into +/// `out`, a vector at a time, a newline's place off its mask (a search for +/// each cost a short line ~57 instructions); and the most bytes of `bytes` +/// between two newlines or an end. +fn fillLines(bytes: []const u8, off: usize, out: []usize) usize { + const Mask = @Int(.unsigned, lanes); + var n: usize = 0; + var from: usize = 0; + var widest: usize = 0; + var i: usize = 0; + while (i + lanes <= bytes.len) : (i += lanes) { + const v: Lanes = bytes[i..][0..lanes].*; + var nl: Mask = @bitCast(v == @as(Lanes, @splat('\n'))); + while (nl != 0) : (nl &= nl - 1) { + const at = i + @ctz(nl); + widest = @max(widest, at - from); + from = at + 1; + out[n] = off + from; + n += 1; + } + } + for (bytes[i..], i..) |b, at| if (b == '\n') { + widest = @max(widest, at - from); + from = at + 1; + out[n] = off + from; + n += 1; + }; + return @max(widest, bytes.len - from); +} + /// The whole buffer of a text's bytes, its room past them included. fn textRoom(f: *const State) []u8 { return f.content.ptr[0..@max(f.cap, f.content.len)]; @@ -668,7 +756,10 @@ pub const Span = struct { head: usize, tail: usize }; fn shiftIndex(gpa: std.mem.Allocator, f: *State, off: usize, len: usize, bytes: []const u8) void { const starts = f.line_starts; const room = indexRoom(f); - const n = starts.len - (std.sort.upperBound(usize, starts, off + len, ascending) - std.sort.upperBound(usize, starts, off, ascending)) + std.mem.count(u8, bytes, "\n"); + const first = std.sort.upperBound(usize, starts, off, ascending); + const found = countLines(bytes); + const added = found.newlines; + const n = starts.len - (std.sort.upperBound(usize, starts, off + len, ascending) - first) + added; var out = room; if (n > room.len) { out = gpa.alloc(usize, n + @max(n / 8, 512)) catch { @@ -679,10 +770,17 @@ fn shiftIndex(gpa: std.mem.Allocator, f: *State, off: usize, len: usize, bytes: }; @memcpy(out[0..starts.len], starts); } else pardes.rollback.Epoch.wrote(gpa, usize, room, starts.len, n, off, f.content[off..][0..len], bytes.len); - shiftStarts(out, starts.len, n, off, len, bytes); + const inside = shiftStarts(out, starts.len, n, off, len, bytes); if (out.ptr != room.ptr) pardes.memory.freeRaw(gpa, room); f.line_starts = out[0..n]; f.line_cap = out.len; + // The widest: what the edit put in, and the two lines it joined at + // its ends (the line `off` is on, the one its last newline starts). + const total = f.content.len - len + bytes.len; + const ends = [2]usize{ first - 1, first - 1 + added }; + var widest = @max(f.widest.bytes, inside); + for (ends) |l| widest = @max(widest, (if (l + 1 < n) f.line_starts[l + 1] - 1 else total) - f.line_starts[l]); + f.widest = .{ .bytes = widest, .tabbed = f.widest.tabbed or found.tabbed }; } /// The first `len` of `room`, a line index, through the edit that puts @@ -692,7 +790,8 @@ fn shiftIndex(gpa: std.mem.Allocator, f: *State, off: usize, len: usize, bytes: /// only the moving is a pass over the index, and only from the edit on. The /// edit turned round (`cut` its length in, `bytes` what it took out) gives /// the index before it back: a rollback's (core/rollback.zig `unwrite`). -pub fn shiftStarts(room: []usize, len: usize, n: usize, off: usize, cut: usize, bytes: []const u8) void { +/// The most bytes of `bytes` between two newlines or an end (fillLines). +pub fn shiftStarts(room: []usize, len: usize, n: usize, off: usize, cut: usize, bytes: []const u8) usize { const starts = room[0..len]; const kept = std.sort.upperBound(usize, starts, off, ascending); const moved = len - std.sort.upperBound(usize, starts, off + cut, ascending); @@ -709,13 +808,7 @@ pub fn shiftStarts(room: []usize, len: usize, n: usize, off: usize, cut: usize, } else for (0..moved) |k| { room[to + k] = room[from + k] - cut + bytes.len; } - var i = kept; - var at: usize = 0; - while (std.mem.indexOfScalarPos(u8, bytes, at, '\n')) |nl| { - at = nl + 1; - room[i] = off + at; - i += 1; - } + return fillLines(bytes, off, room[kept..]); } /// line count, O(1) once the index is warm @@ -982,9 +1075,9 @@ pub fn relayer(p: *Pardes, f: *State, new: []u8, spans: []ReadOnly, layer: u32) // selection's anchor and ranges in the live view, a cursor and a top // line in the others. const Place = struct { row: *i32, col: *i32, at: usize }; - const Top = struct { line: *usize, at: usize }; + const Kept = struct { line: *usize, at: usize }; var places: std.ArrayList(Place) = .empty; - var tops: std.ArrayList(Top) = .empty; + var tops: std.ArrayList(Kept) = .empty; const At = struct { fn of(q: *Pardes, g: *State, row: i32, col: i32) usize { const r: usize = @intCast(@max(0, row)); @@ -1031,7 +1124,7 @@ pub fn relayer(p: *Pardes, f: *State, new: []u8, spans: []ReadOnly, layer: u32) place.row.* = @intCast(pos.row); place.col.* = @intCast(pos.col); } - for (tops.items) |top| top.line.* = positionIn(p.gpa, f, bufferOffset(f, top.at, false)).row; + for (tops.items) |kept| kept.line.* = positionIn(p.gpa, f, bufferOffset(f, kept.at, false)).row; return true; } @@ -1222,6 +1315,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who tf.cap = f.cap; tf.line_starts = f.line_starts; tf.line_cap = f.line_cap; + tf.widest = f.widest; if (!told and tf.context.revision == f.revision -% 1) tf.context.revision = f.revision; // Its copy of the read-only lines, moved as this one's were (the // layer's own edit sets them after, jj.showLayer). @@ -1409,6 +1503,7 @@ pub fn zerox(p: *Pardes, from: usize, to: usize) !*Pane { .cap = f.cap, .line_starts = f.line_starts, .line_cap = f.line_cap, + .widest = f.widest, .history = f.history, .revision = f.revision, .saved_revision = f.saved_revision, @@ -1419,6 +1514,7 @@ pub fn zerox(p: *Pardes, from: usize, to: usize) !*Pane { .on_disk = f.on_disk, .mtime = f.mtime, .scroll = f.scroll, + .scroll_row = f.scroll_row, .tree_context = f.tree_context, .twin = f.twin, }; @@ -1650,11 +1746,309 @@ fn pageEnd(tab: u16, pane: *Pane) usize { } fn setPageScroll(pane: *Pane, line: usize) void { + setTop(pane, .{ .line = @min(line, nlines(pane.gpa, &pane.file.?) -| 1) }); +} + +/// A view's top: the line its first row is of (`State.scroll`) and that +/// row of the line's rows as wrapped (`State.scroll_row`; one row +/// unwrapped). A scroll moves it by rows through the lines. +pub const Top = struct { line: usize, row: u32 = 0 }; + +/// The row of line `line` that shows its byte `col` (a line's last row +/// every byte past its start, as wrapRow has it), as fillBody wraps it. +pub fn rowOf(tab: u16, pane: *const Pane, line: usize, col: usize) u32 { + return rowIn(tab, pane, line, col).row; +} + +/// The rows line `line` takes in `pane`'s view. +pub fn lineRows(tab: u16, pane: *const Pane, line: usize) u32 { + return rowIn(tab, pane, line, std.math.maxInt(usize)).rows; +} + +/// Whether every line of `pane`'s view is one row: none wider than a row +/// (the text's widest, kept with its index), so its rows are its lines and +/// the walks below are line arithmetic, nothing read. +fn oneRow(tab: u16, pane: *const Pane) bool { + const width = wrapWidth(pane, pane.view.wrap); const f = &pane.file.?; - const to = @min(line, nlines(pane.gpa, f) -| 1); - if (to == f.scroll) return; - f.scroll = to; - f.syntax_dirty = true; + return width == 0 or (f.line_starts.len > 0 and f.widest.cells(tab) <= width); +} + +const RowIn = struct { row: u32, rows: u32 }; + +/// rowOf's row and lineRows' rows, in one walk of the line: the one walk +/// of a line's rows every map from rows to lines asks, beside the +/// geometry's own map of the body (the same `fitEnd` at the same width). +fn rowIn(tab: u16, pane: *const Pane, line: usize, col: usize) RowIn { + if (pane.file != null and oneRow(tab, pane)) { + if (builtin.mode == .debug) std.debug.assert(rowWalked(tab, pane, line, col).rows == 1); + return .{ .row = 0, .rows = 1 }; + } + return rowWalked(tab, pane, line, col); +} + +fn rowWalked(tab: u16, pane: *const Pane, line: usize, col: usize) RowIn { + const f = if (pane.file) |*file| file else return .{ .row = 0, .rows = 1 }; + const width = wrapWidth(pane, pane.view.wrap); + if (width == 0) return .{ .row = 0, .rows = 1 }; + const text = sourceLine(pane, @intCast(line)); + // No more bytes than a row has cells and no tab is one row: a tab is + // `tab` cells, any other byte at most one (Widest); no grapheme walked + // (the lines a page or a margin crosses, nearly all of a source's). + if (text.len <= width and std.mem.indexOfScalar(u8, text, '\t') == null) { + if (builtin.mode == .debug) std.debug.assert(fitEnd(tab, text, 0, width) >= text.len); + return .{ .row = 0, .rows = 1 }; + } + var guide: [1024]u8 = undefined; + var at: usize = 0; + var row: u32 = 0; + var found: ?u32 = null; + while (true) { + const end = fitEnd(tab, text, at, width - displayWidth(tab, guideOf(f, text, at, width, &guide))); + if (found == null and col < end) found = row; + if (end >= text.len or end <= at) return .{ .row = found orelse row, .rows = row + 1 }; + at = end; + row += 1; + } +} + +/// Where `pane`'s view starts: a row past its line's last (the text +/// rewrapped, an edit, the layer's lines come or gone) is read as its +/// last, as the geometry's walk found it (no walk of the line a frame). +pub fn top(tab: u16, pane: *Pane) Top { + const f = &pane.file.?; + if (f.scroll_row == 0) return .{ .line = f.scroll }; + geometry(tab, pane); + return .{ .line = f.scroll, .row = pane.top_skip.row }; +} + +pub fn setTop(pane: *Pane, to: Top) void { + const f = &pane.file.?; + if (to.line != f.scroll) f.syntax_dirty = true; + f.scroll = to.line; + f.scroll_row = to.row; +} + +/// The place `n` rows below `from` (above it, `n` negative) through the +/// lines' rows, held at the text's first row and at its last line's last; +/// and the rows it moved. +pub fn walkRows(tab: u16, pane: *Pane, from: Top, n: i64) Walked { + return walkKnown(tab, pane, from, n, null); +} + +/// A line's rows its caller has walked already (show's, the cursor's +/// line): a walk reads them, not the line again. +const Known = struct { line: usize, rows: u32 }; + +const Walked = struct { to: Top, moved: i64 }; + +fn walkKnown(tab: u16, pane: *Pane, from: Top, n: i64, known: ?Known) Walked { + const last = nlines(pane.gpa, &pane.file.?) -| 1; + if (!oneRow(tab, pane)) return walkedRows(tab, pane, from, n, last, known); + const to = if (n < 0) from.line -| @abs(n) else if (from.line >= last) from.line else @min(from.line +| @abs(n), last); + const w: Walked = .{ .to = .{ .line = to }, .moved = @as(i64, @intCast(to)) - @as(i64, @intCast(from.line)) }; + if (builtin.mode == .debug) std.debug.assert(std.meta.eql(w, walkedRows(tab, pane, from, n, last, known))); + return w; +} + +fn walkedRows(tab: u16, pane: *Pane, from: Top, n: i64, last: usize, known: ?Known) Walked { + const map = mapFresh(pane); + var t = from; + var rows = rowsOf(tab, pane, map, known, t.line); + t.row = @min(t.row, rows - 1); + var left = n; + while (left > 0) { + const room = rows - 1 - t.row; + if (left <= room) { + t.row += @intCast(left); + left = 0; + } else if (t.line >= last) { + left -= room; + t.row = rows - 1; + break; + } else { + left -= room + 1; + t.line += 1; + t.row = 0; + rows = rowsOf(tab, pane, map, known, t.line); + } + } + while (left < 0) { + if (-left <= t.row) { + t.row -= @intCast(-left); + left = 0; + } else if (t.line == 0) { + left += t.row; + t.row = 0; + break; + } else { + left += t.row + 1; + t.line -= 1; + rows = rowsOf(tab, pane, map, known, t.line); + t.row = rows - 1; + } + } + return .{ .to = t, .moved = n - left }; +} + +/// The rows from `from` down to line `line`'s first row (up to it, +/// negative), or null when it is more than `bound` rows away. +pub fn rowsTo(tab: u16, pane: *const Pane, from: Top, line: usize, bound: u32) ?i64 { + if (!oneRow(tab, pane)) return rowsWalked(tab, pane, from, line, bound); + const d = @as(i64, @intCast(line)) - @as(i64, @intCast(from.line)) - from.row; + const to: ?i64 = if ((line > from.line and d > bound) or (line < from.line and -d > bound)) null else d; + if (builtin.mode == .debug) std.debug.assert(std.meta.eql(to, rowsWalked(tab, pane, from, line, bound))); + return to; +} + +fn rowsWalked(tab: u16, pane: *const Pane, from: Top, line: usize, bound: u32) ?i64 { + const map = mapFresh(pane); + var d: i64 = -@as(i64, from.row); + var l = from.line; + while (l < line) : (l += 1) { + d += rowsOf(tab, pane, map, null, l); + if (d > bound) return null; + } + while (l > line) { + l -= 1; + d -= rowsOf(tab, pane, map, null, l); + if (-d > bound) return null; + } + return d; +} + +/// Whether `pane`'s map (the geometry) is of the view as it is now: only +/// then may a walk read a line's rows off it (derived state, made by +/// whoever asked first). +fn mapFresh(pane: *const Pane) bool { + return pane.wrap_n > 0 and pane.geometry_key == geometryKey(pane, &pane.file.?); +} + +/// The rows line `line` takes: counted off the map when the map is fresh +/// and holds all of them in the body (no line walked: a page, a cursor +/// past the body's edge), else walked (lineRows). +fn rowsOf(tab: u16, pane: *const Pane, map: bool, known: ?Known, line: usize) u32 { + if (known) |k| if (k.line == line) return k.rows; + if (map and pane.wrap_n > pane.context_rows and line >= pane.wrap_line[pane.context_rows] and line <= pane.wrap_line[pane.wrap_n - 1]) { + const f = &pane.file.?; + var rows: u32 = 0; + var i: usize = pane.context_rows; + while (i < pane.wrap_n) : (i += 1) { + if (pane.wrap_line[i] == line) { + // Rows of it above the top are not in the map. + if (rows == 0 and i == pane.context_rows and line == f.scroll and pane.top_skip.row > 0) break; + rows += 1; + } else if (rows > 0) return rows; + } + } + return lineRows(tab, pane, line); +} + +/// `pane`'s view moved `delta` rows (a wheel's notch is one): the rows it +/// moved. +pub fn scrollRows(tab: u16, pane: *Pane, delta: i64) i64 { + geometry(tab, pane); + const t = top(tab, pane); + // Down to a row the body shows: the map has it, its line and its row in + // that line, no line walked (a notch, a page). + const i = @as(i64, pane.context_rows) + delta; + if (delta > 0 and pane.wrap_n > 0 and i < shownRows(tab, pane) + @as(i64, pane.context_rows)) { + const k: usize = @intCast(i); + const line: usize = @intCast(pane.wrap_line[k]); + if (line < nlines(pane.gpa, &pane.file.?)) { + var row: u32 = if (line == t.line) t.row else 0; + for (pane.wrap_line[pane.context_rows..k]) |l| row += @intFromBool(l == pane.wrap_line[k]); + setTop(pane, .{ .line = line, .row = row }); + return delta; + } + } + const w = walkRows(tab, pane, t, delta); + setTop(pane, w.to); + return w.moved; +} + +/// The rows of `pane`'s body under its context rows, of its geometry as +/// the view is now (made again first if stale: a key's step reads it +/// before any draw, and only the state it is made of may decide it). +pub fn shownRows(tab: u16, pane: *Pane) u16 { + geometry(tab, pane); + const visible = if (pane.body_visible_rows > 0) @min(pane.wrap_n, pane.body_visible_rows) else pane.wrap_n; + return @max(1, if (pane.wrap_n == 0) pane.rows else visible -| pane.context_rows); +} + +/// The view moved when line `line_at`'s row that shows its byte `col` is +/// out of the body's margins (`margin_rows` rows, helix's scrolloff, at +/// most half of it): by the rows that show the line's rows whole inside +/// them, or that row where the line is taller than they leave. A cursor's +/// (Pane.ensureCursorVisible's, for a file) or a result's. +pub fn show(tab: u16, pane: *Pane, line_at: i32, col: i32, margin_rows: i64) void { + const f = &pane.file.?; + geometry(tab, pane); + const t = top(tab, pane); + // The line held at the top (a sticky context row): as it is. + if (pane.context_rows < pane.wrap_n and pane.wrap_line[pane.context_rows] == t.line) { + for (pane.wrap_line[0..pane.context_rows]) |row| if (row == line_at) return; + } + const body: i64 = shownRows(tab, pane); + const margin: i64 = @min(margin_rows, @divTrunc(body - 1, 2)); + // The row in the body (the map's, made just now), or none: the line is + // above the top, or below the map. Inside the band the view stays, and + // no line is walked (a key's step, nearly always). + const mapped: i64 = pane.wrapRow(tab, line_at, col).row - @as(i64, pane.context_rows); + const row: ?i64 = if (mapped >= 0 and mapped < @max(pane.wrap_n, pane.rows) -| pane.context_rows) mapped else null; + if (row) |r| if (r >= margin and r <= body - 1 - margin) return; + const line: usize = @intCast(@max(0, line_at)); + const at = rowIn(tab, pane, line, @intCast(@max(0, col))); + const known: Known = .{ .line = line, .rows = at.rows }; + if (pane.follow_edges != 0 and (row == null or row.? < 0 or row.? >= body)) pane.follow_crossed = true; + const whole = at.rows <= body - 2 * margin; + if (if (row) |r| r < margin else line <= t.line) { + if (pane.follow_edges & 1 != 0) return; + setTop(pane, walkKnown(tab, pane, .{ .line = line, .row = if (whole) 0 else at.row }, -margin, known).to); + } else if (if (row) |r| r > body - 1 - margin else true) { + if (pane.follow_edges & 2 != 0) return; + // The margin only reveals text: a pane its whole text fits in + // never scrolls for it; a longer one keeps helix's clamp at the + // text's last line. + var past = walkKnown(tab, pane, .{ .line = line, .row = if (whole) at.rows - 1 else at.row }, margin, known).to; + if (t.line == 0 and t.row == 0 and pane.textFits()) { + const stop = @max(line, nlines(pane.gpa, f) -| 1 -| @intFromBool(std.mem.endsWith(u8, f.content, "\n"))); + if (past.line > stop) past = .{ .line = stop, .row = lineRows(tab, pane, stop) - 1 }; + } + setTop(pane, walkKnown(tab, pane, past, -(body - 1), known).to); + } +} + +/// The line whose first row (no wrapped line's later row) is nearest body +/// row `from` inside the body's band (`margin` rows in from each edge, at +/// most half of it, under its context rows): the first at or below it +/// going `.down`, else the last above it; `.up` the other way round. Where +/// a view key leaves a cursor (Text.scrollViewMove, normal.halfPageMove); +/// null when the band has none (inside a line taller than the body): the +/// cursor stays. +pub fn textRowLine(tab: u16, pane: *Pane, from: i64, margin: i64, way: enum { down, up }) ?i32 { + geometry(tab, pane); + const lines: i32 = @intCast(nlines(pane.gpa, &pane.file.?)); + const held: i64 = pane.context_rows; + const shown: i64 = shownRows(tab, pane); + const m = @min(margin, @divTrunc(shown - 1, 2)); + const lo = held + m; + const hi = held + shown - 1 - m; + for ([2]i64{ if (way == .down) 1 else -1, if (way == .down) -1 else 1 }) |step| { + var vr = std.math.clamp(held + from, lo, hi); + while (vr >= lo and vr <= hi) : (vr += step) { + const w = pane.wrapAt(tab, @intCast(vr)); + if ((w.at == 0 or !pane.body_wrapped) and w.line < lines) return w.line; + } + } + return null; +} + +/// A call stack's row after its line's first starts with its tree's guide +/// (locations.treeContinuation), in `buffer`; any other row with none. +fn guideOf(f: *const State, text: []const u8, at: usize, width: usize, buffer: *[1024]u8) []const u8 { + if (at == 0 or width <= 1 or f.output == null or !std.meta.eql(f.output.?.from, Output.Origin{ .query = .callstack })) return ""; + return locations.treeContinuation(text, buffer, width - 1); } /// `pane` out of its Follow chain (Unfollow, or a chain down to it): a @@ -2131,12 +2525,12 @@ fn prepareContextRows(pane: *Pane, file: *State) void { if (!file.tree_context or !supportsContext(pane) or pane.rows > pane.wrap_line.len) return; const capacity = @min(pane.rows -| 1, pane.context_row_limit orelse std.math.maxInt(u16)); // retain an ordinary body row // The declarations are the file's lines; the rows, the buffer's. - const top = fileRow(file, file.scroll); + const top_line = fileRow(file, file.scroll); for (file.context.declarations) |declaration| { - if (declaration.start_line >= top) break; - if (declaration.end_line < top) continue; + if (declaration.start_line >= top_line) break; + if (declaration.end_line < top_line) continue; var line = declaration.start_line; - while (line <= declaration.header_end_line and line < top) : (line += 1) { + while (line <= declaration.header_end_line and line < top_line) : (line += 1) { if (pane.context_rows >= capacity) return; const row = bufferRow(file, line); if (pane.context_rows > 0 and row <= pane.wrap_line[pane.context_rows - 1]) continue; @@ -2186,6 +2580,11 @@ pub fn geometry(tab: u16, pane: *Pane) void { const key = geometryKey(pane, f); if (pane.geometry_key == key) return; pane.geometry_key = key; + // The key of what the map was made from: the walk brings the text's + // index and tables up to it (`line_starts`, `tables.revision`, in the + // key), and with the key from before, a step's second ask made it all + // again. + defer pane.geometry_key = geometryKey(pane, f); pane.body_rows = 0; pane.body_visible_rows = 0; pane.context_row_limit = null; @@ -2228,7 +2627,7 @@ fn geometryKey(pane: *const Pane, f: *const State) u64 { if (f.output) |o| pardes.walk.digest(Output.Origin, &o.from) else 0, std.hash.Wyhash.hash(0, f.path), f.tree_context, f.context.revision orelse 0, f.context.declarations.len, f.line_starts.len, t.revision orelse 0, t.list.items.len, pane.view.wrap, pane.view.layered, pane.view.body_h, pane.view.tagline_h, - pane.view.rect_h, laneCells(pane) + @as(u16, pane.layers.heat), + pane.view.rect_h, laneCells(pane) + @as(u16, pane.layers.heat), f.scroll_row, }; // One hash of them laid out as words: every reader of the map asks for // this key, a hundred times a frame. @@ -2256,6 +2655,20 @@ fn fillBody(comptime layered: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State var body_line: usize = f.scroll; var body_at: usize = 0; var written: usize = 0; + var guide_buffer: [1024]u8 = undefined; + // The top line from the view's row in it (`top`): the rows above + // skipped, never past its last; walked once a geometry (the map's + // pass), its text's pass a frame starting where that walk ended. + if (record_wrap) { + var skipped: u32 = 0; + while (skipped < f.scroll_row and width > 0 and body_line < total) : (skipped += 1) { + const text = sourceLine(pane, @intCast(body_line)); + const end = fitEnd(tab, text, body_at, width - displayWidth(tab, guideOf(f, text, body_at, width, &guide_buffer))); + if (end >= text.len or end <= body_at) break; + body_at = end; + } + pane.top_skip = .{ .row = skipped, .at = body_at }; + } else body_at = pane.top_skip.at; for (0..if (pane.body_rows > 0) pane.body_rows else pane.rows) |i| { if (i > 0) { if (dst) |out| out[written] = '\n'; @@ -2265,12 +2678,7 @@ fn fillBody(comptime layered: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State const row = if (context) @as(usize, @intCast(pane.wrap_line[i])) else body_line; const at = if (context) 0 else body_at; const text = if (row < total) sourceLine(pane, @intCast(row)) else ""; - var guide_buffer: [1024]u8 = undefined; - const guide = if (at > 0 and width > 1 and f.output != null and - std.meta.eql(f.output.?.from, Output.Origin{ .query = .callstack })) - locations.treeContinuation(text, &guide_buffer, width - 1) - else - ""; + const guide = guideOf(f, text, at, width, &guide_buffer); const pad = displayWidth(tab, guide); // Headers use one screen row per source row, preserving signatures // without allowing a long ancestor to consume the whole viewport. @@ -2709,6 +3117,11 @@ test "the ASCII run in fitEnd survives an exhaustive byte sweep" { } test "the ASCII run in fitEnd cuts where the grapheme walk would" { + const run = struct { + fn of(comptime c: u8, comptime n: usize) [n]u8 { + return @splat(c); + } + }.of; const reference = struct { fn fitEnd(text: []const u8, start: usize, width: usize) usize { var end = start; @@ -2739,6 +3152,12 @@ test "the ASCII run in fitEnd cuts where the grapheme walk would" { // an ASCII byte followed by a continuation byte is NOT its own cluster "e\u{0301}x", "\u{1f1e6}\u{1f1e7}ok", + // runs longer than a vector (the vector loop), each ending at a + // non-ASCII byte, a combining mark, a tab, or the text's end + &(run('x', 40) ++ "\u{00e9}".* ++ run('y', 40)), + &(run('a', 32) ++ "\u{0301}".* ++ run('b', 17)), + &(run('c', 47) ++ "\t".* ++ run('d', 20)), + &run('z', 100), }; for (cases) |text| { var width: usize = 0; @@ -2769,7 +3188,7 @@ test "a line index shifted in place equals a rebuilt one, and the edit turned ro const del = r.uintAtMost(usize, @min(12, text.items.len - at)); var ins: [12]u8 = undefined; const ins_len = r.uintAtMost(usize, 12); - for (ins[0..ins_len]) |*c| c.* = "ab\n"[r.uintLessThan(usize, 3)]; + for (ins[0..ins_len]) |*c| c.* = "ab\n\t"[r.uintLessThan(usize, 4)]; const before = try gpa.dupe(usize, f.line_starts); defer gpa.free(before); const cut = try gpa.dupe(u8, text.items[at..][0..del]); @@ -2781,12 +3200,18 @@ test "a line index shifted in place equals a rebuilt one, and the edit turned ro const want = try lineIndex(gpa, &fresh); defer gpa.free(want); try std.testing.expectEqualSlices(usize, want, f.line_starts); + // The kept widest is never less than the text's, made anew exact. + var widest: usize = 0; + var lines = std.mem.splitScalar(u8, text.items, '\n'); + while (lines.next()) |line| widest = @max(widest, line.len); + try std.testing.expectEqual(Widest{ .bytes = widest, .tabbed = std.mem.indexOfScalar(u8, text.items, '\t') != null }, fresh.widest); + try std.testing.expect(f.widest.bytes >= widest and (f.widest.tabbed or !fresh.widest.tabbed)); // Every tenth turned round in a copy, as a rollback takes it back. if (round % 10 == 0) { const room = try gpa.alloc(usize, indexRoom(&f).len); defer gpa.free(room); @memcpy(room[0..f.line_starts.len], f.line_starts); - shiftStarts(room, f.line_starts.len, before.len, at, ins_len, cut); + _ = shiftStarts(room, f.line_starts.len, before.len, at, ins_len, cut); try std.testing.expectEqualSlices(usize, before, room[0..before.len]); } } -- cgit v1.3 From cdab9ba0f0fdb433217f6b408ef81357176fa965 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 18:20:56 -0300 Subject: perf: a long wrapped line's row walks cut to the rows the view needs, each row's end found without a grapheme step, the top's byte handed to the geometry by the step that found it, the geometry's key hashed once a step (P62 round 3, item 2): perfops against tree6 from 11 of 121 over (item 1's tree: body-appends on longline +18.2%, client-key-down on longline +1.44%) to 10 (deep-sel's eight, the view drawing the selection deep in its 2 MB line; body-appends on longline's SETUP +0.66%, derived; client-key-down on longline +0.44%; terminal on all +0.12%, below the base's own ruled +0.14%), body-appends on longline per-op -7.4%, every key, wheel, page and edit cell at or under tree6; each cut found by Intel PT by symbol (`.scratch/sketch/reorg/pardes-row-scroll-3/pt-*.txt`): `fitEnd` ended every full row with a grapheme step to learn the next byte did not fit (~118 instructions a row): a full row before a printable ASCII byte that no non-ASCII byte follows now ends there, and the rest of a row of printable ASCII past the vector loop is one masked vector (both checked by the exhaustive fitEnd tests); `show` walks the cursor's line once and no further than it needs (`Bound`: `margin` rows past the cursor's and `body - 2 margin + 1` in all, its rows a lower bound then, which its walks never pass), keeping the first bytes of its last rows in a ring on the stack, and where the view lands in that line hands that byte to the geometry (`Pane.top_skip` gains the `key` of the geometry it is for: fillBody walks to the top's row only for a key no step found it for); a wheel's notch down off the map hands the map's byte the same way; `show` and `scrollRows` hash the geometry's key once (`topNow`, `shownNow`; ensureCursorVisible's extra `geometry` call gone) and a walk asks whether the map is fresh only when it reads a line off it; `rowsOf` walks a line with the walk's width (`rowWalked`), not through `rowIn`'s one-row check again; Debug in the workspace: core-test 963/1129 (166 skipped) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/File.zig | 113 ++++++++++++++++++++++++++++++++++++++++++--------------- core/panes.zig | 10 ++--- 2 files changed, 88 insertions(+), 35 deletions(-) (limited to 'core/File.zig') diff --git a/core/File.zig b/core/File.zig index 86861792..b2439b29 100644 --- a/core/File.zig +++ b/core/File.zig @@ -622,6 +622,14 @@ pub fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize { used += lanes; end += lanes; } + // The rest of a row of printable ASCII in one vector more: its bytes and + // the two after them printable ASCII, the row ends where the width does + // (what the loops below find a byte at a time). + if (used < width and width - used + 2 <= lanes and end + lanes <= text.len) { + const v: Lanes = text[end..][0..lanes].*; + const bad: @Int(.unsigned, lanes) = @bitCast(v -% @as(Lanes, @splat(0x20)) >= @as(Lanes, @splat(0x5f))); + if (@ctz(bad) >= width - used + 2) return end + (width - used); + } while (used < width and end < text.len) { const b = text[end]; if (b < 0x20 or b >= 0x7f) break; @@ -629,6 +637,10 @@ pub fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize { used += 1; end += 1; } + // A full row before a printable ASCII byte no non-ASCII byte follows (a + // grapheme of its own, a cell wide): the row ends there, nothing walked + // (every wrapped row ends so, and the walk cost a row a hundred more). + if (used == width and end > start and end < text.len and text[end] -% 0x20 < 0x5f and (end + 1 == text.len or text[end + 1] < 0x80)) return end; while (end < text.len) { const next_end = modal.nextGrapheme(text, end); const next_used = used +| graphemeDisplayWidth(tab, text[end..next_end]); @@ -1768,8 +1780,7 @@ pub fn lineRows(tab: u16, pane: *const Pane, line: usize) u32 { /// Whether every line of `pane`'s view is one row: none wider than a row /// (the text's widest, kept with its index), so its rows are its lines and /// the walks below are line arithmetic, nothing read. -fn oneRow(tab: u16, pane: *const Pane) bool { - const width = wrapWidth(pane, pane.view.wrap); +fn oneRow(tab: u16, pane: *const Pane, width: usize) bool { const f = &pane.file.?; return width == 0 or (f.line_starts.len > 0 and f.widest.cells(tab) <= width); } @@ -1780,16 +1791,24 @@ const RowIn = struct { row: u32, rows: u32 }; /// of a line's rows every map from rows to lines asks, beside the /// geometry's own map of the body (the same `fitEnd` at the same width). fn rowIn(tab: u16, pane: *const Pane, line: usize, col: usize) RowIn { - if (pane.file != null and oneRow(tab, pane)) { - if (builtin.mode == .debug) std.debug.assert(rowWalked(tab, pane, line, col).rows == 1); + const width = wrapWidth(pane, pane.view.wrap); + if (pane.file != null and oneRow(tab, pane, width)) { + if (builtin.mode == .debug) std.debug.assert(rowWalked(tab, pane, width, line, col, .{}, &.{}).rows == 1); return .{ .row = 0, .rows = 1 }; } - return rowWalked(tab, pane, line, col); + return rowWalked(tab, pane, width, line, col, .{}, &.{}); } -fn rowWalked(tab: u16, pane: *const Pane, line: usize, col: usize) RowIn { +/// How far a walk of a line's rows goes once the row showing its byte is +/// found: `after` rows past it and `least` in all, its rows a lower bound +/// then (what `show` needs of a long line); else to its end. +const Bound = struct { after: u32 = std.math.maxInt(u32), least: u32 = 0 }; + +/// rowIn's walk at `width`, as far as `bound`; `starts`, when it has room, +/// keeps the first byte of each row walked after the first, the last +/// `starts.len` of them (row `r` at `r % starts.len`; its caller's row 0). +fn rowWalked(tab: u16, pane: *const Pane, width: usize, line: usize, col: usize, bound: Bound, starts: []usize) RowIn { const f = if (pane.file) |*file| file else return .{ .row = 0, .rows = 1 }; - const width = wrapWidth(pane, pane.view.wrap); if (width == 0) return .{ .row = 0, .rows = 1 }; const text = sourceLine(pane, @intCast(line)); // No more bytes than a row has cells and no tab is one row: a tab is @@ -1807,8 +1826,10 @@ fn rowWalked(tab: u16, pane: *const Pane, line: usize, col: usize) RowIn { const end = fitEnd(tab, text, at, width - displayWidth(tab, guideOf(f, text, at, width, &guide))); if (found == null and col < end) found = row; if (end >= text.len or end <= at) return .{ .row = found orelse row, .rows = row + 1 }; + if (found) |r| if (row >= r +| bound.after and row + 1 >= bound.least) return .{ .row = r, .rows = row + 1 }; at = end; row += 1; + if (starts.len > 0) starts[row % starts.len] = at; } } @@ -1816,10 +1837,15 @@ fn rowWalked(tab: u16, pane: *const Pane, line: usize, col: usize) RowIn { /// rewrapped, an edit, the layer's lines come or gone) is read as its /// last, as the geometry's walk found it (no walk of the line a frame). pub fn top(tab: u16, pane: *Pane) Top { + if (pane.file.?.scroll_row > 0) geometry(tab, pane); + return topNow(pane); +} + +/// `top` off a geometry made already (a step that made it reads its key +/// once: each hash of it costs a long line's step a hundredth more). +fn topNow(pane: *const Pane) Top { const f = &pane.file.?; - if (f.scroll_row == 0) return .{ .line = f.scroll }; - geometry(tab, pane); - return .{ .line = f.scroll, .row = pane.top_skip.row }; + return .{ .line = f.scroll, .row = if (f.scroll_row == 0) 0 else pane.top_skip.row }; } pub fn setTop(pane: *Pane, to: Top) void { @@ -1844,7 +1870,7 @@ const Walked = struct { to: Top, moved: i64 }; fn walkKnown(tab: u16, pane: *Pane, from: Top, n: i64, known: ?Known) Walked { const last = nlines(pane.gpa, &pane.file.?) -| 1; - if (!oneRow(tab, pane)) return walkedRows(tab, pane, from, n, last, known); + if (!oneRow(tab, pane, wrapWidth(pane, pane.view.wrap))) return walkedRows(tab, pane, from, n, last, known); const to = if (n < 0) from.line -| @abs(n) else if (from.line >= last) from.line else @min(from.line +| @abs(n), last); const w: Walked = .{ .to = .{ .line = to }, .moved = @as(i64, @intCast(to)) - @as(i64, @intCast(from.line)) }; if (builtin.mode == .debug) std.debug.assert(std.meta.eql(w, walkedRows(tab, pane, from, n, last, known))); @@ -1852,9 +1878,10 @@ fn walkKnown(tab: u16, pane: *Pane, from: Top, n: i64, known: ?Known) Walked { } fn walkedRows(tab: u16, pane: *Pane, from: Top, n: i64, last: usize, known: ?Known) Walked { - const map = mapFresh(pane); + var map: ?bool = null; + const width = wrapWidth(pane, pane.view.wrap); var t = from; - var rows = rowsOf(tab, pane, map, known, t.line); + var rows = rowsOf(tab, pane, width, &map, known, t.line); t.row = @min(t.row, rows - 1); var left = n; while (left > 0) { @@ -1870,7 +1897,7 @@ fn walkedRows(tab: u16, pane: *Pane, from: Top, n: i64, last: usize, known: ?Kno left -= room + 1; t.line += 1; t.row = 0; - rows = rowsOf(tab, pane, map, known, t.line); + rows = rowsOf(tab, pane, width, &map, known, t.line); } } while (left < 0) { @@ -1884,7 +1911,7 @@ fn walkedRows(tab: u16, pane: *Pane, from: Top, n: i64, last: usize, known: ?Kno } else { left += t.row + 1; t.line -= 1; - rows = rowsOf(tab, pane, map, known, t.line); + rows = rowsOf(tab, pane, width, &map, known, t.line); t.row = rows - 1; } } @@ -1894,7 +1921,7 @@ fn walkedRows(tab: u16, pane: *Pane, from: Top, n: i64, last: usize, known: ?Kno /// The rows from `from` down to line `line`'s first row (up to it, /// negative), or null when it is more than `bound` rows away. pub fn rowsTo(tab: u16, pane: *const Pane, from: Top, line: usize, bound: u32) ?i64 { - if (!oneRow(tab, pane)) return rowsWalked(tab, pane, from, line, bound); + if (!oneRow(tab, pane, wrapWidth(pane, pane.view.wrap))) return rowsWalked(tab, pane, from, line, bound); const d = @as(i64, @intCast(line)) - @as(i64, @intCast(from.line)) - from.row; const to: ?i64 = if ((line > from.line and d > bound) or (line < from.line and -d > bound)) null else d; if (builtin.mode == .debug) std.debug.assert(std.meta.eql(to, rowsWalked(tab, pane, from, line, bound))); @@ -1902,16 +1929,17 @@ pub fn rowsTo(tab: u16, pane: *const Pane, from: Top, line: usize, bound: u32) ? } fn rowsWalked(tab: u16, pane: *const Pane, from: Top, line: usize, bound: u32) ?i64 { - const map = mapFresh(pane); + var map: ?bool = null; + const width = wrapWidth(pane, pane.view.wrap); var d: i64 = -@as(i64, from.row); var l = from.line; while (l < line) : (l += 1) { - d += rowsOf(tab, pane, map, null, l); + d += rowsOf(tab, pane, width, &map, null, l); if (d > bound) return null; } while (l > line) { l -= 1; - d -= rowsOf(tab, pane, map, null, l); + d -= rowsOf(tab, pane, width, &map, null, l); if (-d > bound) return null; } return d; @@ -1926,10 +1954,17 @@ fn mapFresh(pane: *const Pane) bool { /// The rows line `line` takes: counted off the map when the map is fresh /// and holds all of them in the body (no line walked: a page, a cursor -/// past the body's edge), else walked (lineRows). -fn rowsOf(tab: u16, pane: *const Pane, map: bool, known: ?Known, line: usize) u32 { +/// past the body's edge), else walked (a walk's: no line is one row). Its +/// walk's `map`: whether the map is fresh, asked the first time a line in +/// it is. +fn rowsOf(tab: u16, pane: *const Pane, width: usize, map: *?bool, known: ?Known, line: usize) u32 { if (known) |k| if (k.line == line) return k.rows; - if (map and pane.wrap_n > pane.context_rows and line >= pane.wrap_line[pane.context_rows] and line <= pane.wrap_line[pane.wrap_n - 1]) { + if (pane.wrap_n > pane.context_rows and line >= pane.wrap_line[pane.context_rows] and line <= pane.wrap_line[pane.wrap_n - 1] and + (map.* orelse fresh: { + map.* = mapFresh(pane); + break :fresh map.*.?; + })) + { const f = &pane.file.?; var rows: u32 = 0; var i: usize = pane.context_rows; @@ -1941,24 +1976,26 @@ fn rowsOf(tab: u16, pane: *const Pane, map: bool, known: ?Known, line: usize) u3 } else if (rows > 0) return rows; } } - return lineRows(tab, pane, line); + return rowWalked(tab, pane, width, line, std.math.maxInt(usize), .{}, &.{}).rows; } /// `pane`'s view moved `delta` rows (a wheel's notch is one): the rows it /// moved. pub fn scrollRows(tab: u16, pane: *Pane, delta: i64) i64 { geometry(tab, pane); - const t = top(tab, pane); + const t = topNow(pane); // Down to a row the body shows: the map has it, its line and its row in // that line, no line walked (a notch, a page). const i = @as(i64, pane.context_rows) + delta; - if (delta > 0 and pane.wrap_n > 0 and i < shownRows(tab, pane) + @as(i64, pane.context_rows)) { + if (delta > 0 and pane.wrap_n > 0 and i < shownNow(pane) + @as(i64, pane.context_rows)) { const k: usize = @intCast(i); const line: usize = @intCast(pane.wrap_line[k]); if (line < nlines(pane.gpa, &pane.file.?)) { var row: u32 = if (line == t.line) t.row else 0; for (pane.wrap_line[pane.context_rows..k]) |l| row += @intFromBool(l == pane.wrap_line[k]); setTop(pane, .{ .line = line, .row = row }); + // Its first byte is the map's: the geometry starts there. + if (pane.body_wrapped) pane.top_skip = .{ .key = geometryKey(pane, &pane.file.?), .row = row, .at = @intCast(pane.wrap_col[k]) }; return delta; } } @@ -1972,6 +2009,10 @@ pub fn scrollRows(tab: u16, pane: *Pane, delta: i64) i64 { /// before any draw, and only the state it is made of may decide it). pub fn shownRows(tab: u16, pane: *Pane) u16 { geometry(tab, pane); + return shownNow(pane); +} + +fn shownNow(pane: *const Pane) u16 { const visible = if (pane.body_visible_rows > 0) @min(pane.wrap_n, pane.body_visible_rows) else pane.wrap_n; return @max(1, if (pane.wrap_n == 0) pane.rows else visible -| pane.context_rows); } @@ -1984,12 +2025,12 @@ pub fn shownRows(tab: u16, pane: *Pane) u16 { pub fn show(tab: u16, pane: *Pane, line_at: i32, col: i32, margin_rows: i64) void { const f = &pane.file.?; geometry(tab, pane); - const t = top(tab, pane); + const t = topNow(pane); // The line held at the top (a sticky context row): as it is. if (pane.context_rows < pane.wrap_n and pane.wrap_line[pane.context_rows] == t.line) { for (pane.wrap_line[0..pane.context_rows]) |row| if (row == line_at) return; } - const body: i64 = shownRows(tab, pane); + const body: i64 = shownNow(pane); const margin: i64 = @min(margin_rows, @divTrunc(body - 1, 2)); // The row in the body (the map's, made just now), or none: the line is // above the top, or below the map. Inside the band the view stays, and @@ -1998,8 +2039,18 @@ pub fn show(tab: u16, pane: *Pane, line_at: i32, col: i32, margin_rows: i64) voi const row: ?i64 = if (mapped >= 0 and mapped < @max(pane.wrap_n, pane.rows) -| pane.context_rows) mapped else null; if (row) |r| if (r >= margin and r <= body - 1 - margin) return; const line: usize = @intCast(@max(0, line_at)); - const at = rowIn(tab, pane, line, @intCast(@max(0, col))); + // The line walked once and no further than the view needs (`Bound`: a + // long line's rows past the band are not), the first bytes of its last + // rows kept: where the view lands in it, its geometry starts there. + const width = wrapWidth(pane, pane.view.wrap); + var ring: [limits.wrap_rows]usize = undefined; + ring[0] = 0; + const starts = ring[0..@intCast(@min(body, ring.len))]; + const at = if (oneRow(tab, pane, width)) RowIn{ .row = 0, .rows = 1 } else rowWalked(tab, pane, width, line, @intCast(@max(0, col)), .{ .after = @intCast(margin), .least = @intCast(body - 2 * margin + 1) }, starts); const known: Known = .{ .line = line, .rows = at.rows }; + defer if (f.scroll == line and f.scroll_row < at.rows and at.rows - 1 - f.scroll_row < starts.len) { + pane.top_skip = .{ .key = geometryKey(pane, f), .row = f.scroll_row, .at = starts[f.scroll_row % starts.len] }; + }; if (pane.follow_edges != 0 and (row == null or row.? < 0 or row.? >= body)) pane.follow_crossed = true; const whole = at.rows <= body - 2 * margin; if (if (row) |r| r < margin else line <= t.line) { @@ -2659,7 +2710,9 @@ fn fillBody(comptime layered: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State // The top line from the view's row in it (`top`): the rows above // skipped, never past its last; walked once a geometry (the map's // pass), its text's pass a frame starting where that walk ended. - if (record_wrap) { + // A top whose byte a step already found (`show`, a scroll off the map) + // is not walked again. + if (record_wrap and pane.top_skip.key != pane.geometry_key) { var skipped: u32 = 0; while (skipped < f.scroll_row and width > 0 and body_line < total) : (skipped += 1) { const text = sourceLine(pane, @intCast(body_line)); @@ -2667,7 +2720,7 @@ fn fillBody(comptime layered: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State if (end >= text.len or end <= body_at) break; body_at = end; } - pane.top_skip = .{ .row = skipped, .at = body_at }; + pane.top_skip = .{ .key = pane.geometry_key, .row = skipped, .at = body_at }; } else body_at = pane.top_skip.at; for (0..if (pane.body_rows > 0) pane.body_rows else pane.rows) |i| { if (i > 0) { diff --git a/core/panes.zig b/core/panes.zig index b238992a..08d91df5 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -309,10 +309,11 @@ pub const Pane = struct { wrap_n: u16 = 0, /// A row map also exists for sticky headers when soft wrapping is off. body_wrapped: bool = false, - /// Where the geometry's walk found the view's top inside its line's - /// rows (File.Top): the row it is and the bytes of the line before it; - /// a frame's text starts there with no walk again. - top_skip: struct { row: u32 = 0, at: usize = 0 } = .{}, + /// Where the view's top is inside its line's rows (File.Top) for the + /// geometry of `key`: the row it is and the bytes of the line before + /// it, found by the geometry's walk or by the step that put the top + /// there; a frame's text starts there with no walk again. + top_skip: struct { key: u64 = 0, row: u32 = 0, at: usize = 0 } = .{}, context_rows: u16 = 0, body_rows: u16 = 0, body_visible_rows: u16 = 0, @@ -668,7 +669,6 @@ pub const Pane = struct { } pub fn ensureCursorVisible(pane: *Pane, tab: u16) void { - File.geometry(tab, pane); if (pane.file != null) File.show(tab, pane, pane.body.cur_row, pane.body.cur_col, config.scroll_off) else { // A terminal's rows are its lines. const off = pane.scroll(); -- cgit v1.3 From defafb5ccce2ae30d3e16cc8fb57fb73485e03f4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 18:26:46 -0300 Subject: scroll: what still moved by lines now counts rows where a wrapped line made it wrong (P62 round 3, item 3): gt/gb land on the row `scroll_off` rows in from the body's top or its last row of text, a wrapped line's later row as any, the cursor on the first byte that row shows (helix's goto_window), where they went `scroll_off` LINES down from the top line (inside a wrapped line: a line far below, the view moved); gw labels the words of the bytes the body shows (`File.shownBytes`: its first row's first to its last row's last), none on a wrapped line's rows above the view's top (a word the first row starts inside of begins above it: its label would not show), where it labelled the words of `rows` lines from the top line's start; a new pane goes below the rows a pane's text takes (layout.zig `blankRows`: the rows from the view's top to the text's end, `File.rowsTo`, a wrapped line's each), where a pane of a few long lines counted a row a line and had the new pane laid over its text; a Look opening a file in a pane of its own puts its line half the body's rows down, a wrapped line's rows above it counted (look.zig, `walkRows`), where it went half the body's LINES up; TESTS FIRST, each failing on item 1's tree (`qwssppvo`) and passing here: core/normal.zig "gt and gb go to the row scroll_off rows in from the body's top and from its bottom, ..." (the view moved, row 4 to 5), "gw labels the words the body shows and no others: ..." (a label above the top), core/layout.zig "a new pane goes below the rows a pane's text takes, ..." (the pane kept fewer rows than its text), core/look.zig "a Look that opens a file in a pane of its own puts its line half the body's rows down, ..." (24 rows above it, not 17); STILL LINES, each right there: Places' first range (its search pieces are whole lines, so a match is never cut at a piece's edge, and `scroll + rows + 1` lines hold every row shown, each line at least one), the frames' `view` (a statistic's label: no decision reads it), the rail's thumb (rows would wrap the whole text at each width), the syntax window (the rows shown lie inside the lines `scroll .. scroll + rows`) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/File.zig | 17 ++++++++++ core/layout.zig | 35 +++++++++++++++++--- core/look.zig | 37 +++++++++++++++++++-- core/normal.zig | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 179 insertions(+), 11 deletions(-) (limited to 'core/File.zig') diff --git a/core/File.zig b/core/File.zig index b2439b29..8b7adae3 100644 --- a/core/File.zig +++ b/core/File.zig @@ -2095,6 +2095,23 @@ pub fn textRowLine(tab: u16, pane: *Pane, from: i64, margin: i64, way: enum { do return null; } +pub const Bytes = struct { start: usize, end: usize }; + +/// The bytes of the text `pane`'s body shows: its first row's first to its +/// last row's last (whole lines unwrapped, as each row is one). +pub fn shownBytes(tab: u16, pane: *Pane) Bytes { + const f = &pane.file.?; + const shown = shownRows(tab, pane); + if (!pane.body_wrapped) return .{ .start = lineStart(pane.gpa, f, f.scroll), .end = lineStart(pane.gpa, f, f.scroll + shown) }; + const first = pane.context_rows; + const last = first + shown - 1; + const start = lineStart(pane.gpa, f, @intCast(pane.wrap_line[first])) + @as(usize, @intCast(pane.wrap_col[first])); + const line: usize = @intCast(pane.wrap_line[last]); + if (line >= nlines(pane.gpa, f)) return .{ .start = start, .end = f.content.len }; + const text = sourceLine(pane, @intCast(line)); + return .{ .start = start, .end = lineStart(pane.gpa, f, line) + fitEnd(tab, text, @intCast(pane.wrap_col[last]), wrapWidth(pane, pane.view.wrap) -| pane.wrap_pad[last]) }; +} + /// A call stack's row after its line's first starts with its tree's guide /// (locations.treeContinuation), in `buffer`; any other row with none. fn guideOf(f: *const State, text: []const u8, at: usize, width: usize, buffer: *[1024]u8) []const u8 { diff --git a/core/layout.zig b/core/layout.zig index 4c7d6afb..7fa57ee9 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -845,10 +845,14 @@ fn bodyRows(p: *const Pardes, id: usize) u16 { fn blankRows(p: *const Pardes, id: usize) u16 { const pane = p.panes[id].?; const rows = bodyRows(p, id); - const used: usize = if (pane.file) |*f| - // The empty line after a final newline shows nothing. - (panes.File.nlines(p.gpa, f) -| @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) -| f.scroll - else if (pane.isTerminal()) + const used: usize = if (pane.file) |*f| used: { + // The rows from the view's top to the text's end, a wrapped line's + // each; the empty line after a final newline shows nothing. + const end = panes.File.nlines(p.gpa, f) -| @intFromBool(std.mem.endsWith(u8, f.content, "\n")); + const top = panes.File.top(p.settings.tab, pane); + if (end <= top.line) break :used 0; + break :used @intCast(panes.File.rowsTo(p.settings.tab, pane, top, end, rows) orelse rows); + } else if (pane.isTerminal()) @as(usize, panes.Term.grid(pane.terminal).cursor_y) + 1 else rows; @@ -2158,3 +2162,26 @@ test "tiny screens keep pane space before adding a column tag" { try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y); _ = try p.render(p.scratch.allocator()); } + +test "a new pane goes below the rows a pane's text takes, a wrapped line's each counted: a pane whose few lines fill its rows keeps them all" { + const gpa = std.testing.allocator; + const io = std.testing.io; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(io, .{ .sub_path = "b.txt", .data = "other\n" }); + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(io, &buf)]; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 40 }); + defer p.deinit(); + p.settings.wrap = true; + // Two lines of 400 bytes: seven rows each at this width. + const long = &@as([400]u8, @splat('a')); + const pane = try p.setTestFile(long ++ "\n" ++ long ++ "\n"); + const a = p.view().active; + const used = panes.File.lineRows(p.settings.tab, pane, 0) + panes.File.lineRows(p.settings.tab, pane, 1); + try std.testing.expect(used >= 12); + var line: [4200]u8 = undefined; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/b.txt", .{dir}) }); + try std.testing.expect(p.view().active != a); + try std.testing.expect(p.view().rects[a].h -| pane.tag_rows >= used); +} diff --git a/core/look.zig b/core/look.zig index f60b90f5..eee808cb 100644 --- a/core/look.zig +++ b/core/look.zig @@ -1605,11 +1605,13 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // miss of its line too. if (p.fs.failures != failures) return; layout.compute(p); - nt.file.?.scroll -|= @max(1, v.rects[free].h -| BOX_H) / 2; + // Its line half the body's rows down, a wrapped line's + // rows above it counted. + const centered = panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, @max(1, v.rects[free].h -| BOX_H) / 2)).to; + panes.File.setTop(nt, centered); if (target.at.end_line != 0) { - const centered = nt.file.?.scroll; selectSpan(p, nt, target.at); - nt.file.?.scroll = centered; + panes.File.setTop(nt, centered); } opened = free; } @@ -1840,6 +1842,35 @@ test "lookableLineSpan prefers the longest run, so a blank inside a path is one ); } +test "a Look that opens a file in a pane of its own puts its line half the body's rows down, a wrapped line's rows above it counted" { + const gpa = std.testing.allocator; + const io = std.testing.io; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // Line 10 of 600 bytes, eleven rows or more in a pane 60 wide. + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + for (0..60) |i| if (i == 10) { + try text.appendNTimes(gpa, 'a', 600); + try text.append(gpa, '\n'); + } else try text.print(gpa, "line {d:0>2}\n", .{i}); + try tmp.dir.writeFile(io, .{ .sub_path = "c.txt", .data = text.items }); + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(io, &buf)]; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 40 }); + defer p.deinit(); + p.settings.wrap = true; + _ = try p.setTestFile("x\n"); + var line: [4200]u8 = undefined; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/c.txt:14", .{dir}) }); + const id = p.view().active; + const pane = p.panes[id].?; + try std.testing.expect(panes.File.lineRows(p.settings.tab, pane, 10) >= 11); + try std.testing.expectEqual(@as(i32, 13), pane.body.cur_row); + const half: i64 = @max(1, p.view().rects[id].h -| BOX_H) / 2; + try std.testing.expectEqual(half, panes.File.rowsTo(p.settings.tab, pane, panes.File.top(p.settings.tab, pane), 13, 100).?); +} + test "a miss names a long path by its start and its end, its middle given up to …" { var cut: [miss_path_cap + "…".len]u8 = undefined; const long = "/home/someone/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "the-file.zig"; diff --git a/core/normal.zig b/core/normal.zig index 61f8f26b..fe0c729a 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -339,11 +339,22 @@ fn startJump(p: *Pardes, pane: *Pane, t: *Text) edit.Error!void { const text = try edit.flatSurface(p.editor(), t); const cursor = modal.selectionCursor(text, t.primaryRange(text, 0)); const top: usize = @intCast(@max(0, pane.scroll())); - const start = @min(modal.lineStartOffset(text, top), text.len); - const end = @min(modal.lineStartOffset(text, top + pane.rows), text.len); + // A file's words the body shows, its rows' bytes; a terminal's rows + // are its lines. + const shown = if (pane.file != null) File.shownBytes(p.settings.tab, pane) else File.Bytes{ .start = modal.lineStartOffset(text, top), .end = modal.lineStartOffset(text, top + pane.rows) }; + const start = @min(shown.start, text.len); + const end = @min(shown.end, text.len); const letters = config.jump_label_alphabet.len; try pane.jump.resize(p.gpa, letters * letters); - pane.jump.shrinkRetainingCapacity(modal.jumpWords(text, cursor, start, end, pane.jump.items)); + const n = modal.jumpWords(text, cursor, start, end, pane.jump.items); + // A word the body's first row starts inside of (a wrapped line's row + // cut mid-word) begins above it: no label it would not show. + var kept: usize = 0; + for (pane.jump.items[0..n]) |r| if (@min(r.anchor, r.head) >= start) { + pane.jump.items[kept] = r; + kept += 1; + }; + pane.jump.shrinkRetainingCapacity(kept); pane.jump_first = null; } @@ -978,11 +989,28 @@ fn gotoWindow(tab: u16, t: *Text, text: []const u8, range: modal.Selection, whic // a view to move through is a body's; a tag or an answer is all shown if (t.what != .body) return; const w = t.pane() orelse return; + const n: i32 = @intCast(cnt - 1); + if (w.file != null) { + // In rows, as helix's goto_window: the row `margin + n` in from the + // body's top or its last row of text, inside the margins, the + // cursor on the first byte it shows (a wrapped line's later row). + const held: i32 = w.context_rows; + const shown: i32 = File.shownRows(tab, w); + const lines = File.textLineCount(t, text); + var last: i32 = shown - 1; + while (last > 0 and w.wrapAt(tab, held + last).line >= lines) last -= 1; + const margin: i32 = @min(config.scroll_off, @divTrunc(shown - 1, 2)); + const vr = std.math.clamp(@min(@max(switch (which) { + .top => margin + n, + .bottom => last - (margin + n), + }, margin), last - margin), 0, last); + const at = w.wrapAt(tab, held + vr); + return pointMove(tab, t, text, range, File.textLineStart(t, text, @intCast(at.line)) + if (w.body_wrapped) @as(usize, @intCast(at.at)) else 0); + } const margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, w.rows) - 1, 2)); const top = w.scroll(); const last_row: i32 = @intCast(File.textLineCount(t, text) - 1); const last_vis: i32 = @min(@as(i32, w.rows) - 1, last_row - top); - const n: i32 = @intCast(cnt - 1); var vline: i32 = switch (which) { .top => top + margin + n, .bottom => top + last_vis - (margin + n), @@ -1461,6 +1489,71 @@ test "gj/gk step the wrapped rows a body draws while j/k keep the file's lines" try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); } +/// 10 short lines, line 10 of 200 numbered words (17 rows or more at 60 +/// columns), 40 short lines after it; the view's top four rows into line +/// 10, the cursor on a row the body shows. +fn wrappedView(p: *Pardes) !*Pane { + p.settings.wrap = true; + var text: std.ArrayList(u8) = .empty; + defer text.deinit(p.gpa); + for (0..51) |i| if (i == 10) { + for (0..200) |w| try text.print(p.gpa, "w{d:0>3} ", .{w}); + try text.append(p.gpa, '\n'); + } else try text.print(p.gpa, "line {d:0>2}\n", .{i}); + const pane = try p.setTestFile(text.items); + File.setTop(pane, .{ .line = 10, .row = 4 }); + p.sync(); + const at = pane.wrapAt(p.settings.tab, pane.context_rows + 6); + pane.body.cur_row = at.line; + pane.body.cur_col = at.at; + return pane; +} + +test "gt and gb go to the row scroll_off rows in from the body's top and from its bottom, a wrapped line's later row as any, the cursor on its first byte; the view stays" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 24 }); + defer p.deinit(); + const tab = p.settings.tab; + const pane = try wrappedView(p); + const top = File.top(tab, pane); + try std.testing.expectEqual(@as(u32, 4), top.row); + for ("tb") |k| { + p.update(.{ .key = .{ .cp = 'g', .text = "g" } }); + p.update(.{ .key = .{ .cp = k, .text = &[_]u8{k} } }); + try std.testing.expectEqual(top, File.top(tab, pane)); + const row: i32 = if (k == 't') config.scroll_off else File.shownRows(tab, pane) - 1 - config.scroll_off; + const want = pane.wrapAt(tab, pane.context_rows + row); + try std.testing.expectEqual(want.line, pane.body.cur_row); + try std.testing.expectEqual(want.at, pane.body.cur_col); + } +} + +test "gw labels the words the body shows and no others: none on a wrapped line's rows above the view's top" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 24 }); + defer p.deinit(); + const tab = p.settings.tab; + const pane = try wrappedView(p); + p.update(.{ .key = .{ .cp = 'g', .text = "g" } }); + p.update(.{ .key = .{ .cp = 'w', .text = "w" } }); + try std.testing.expect(pane.jump.items.len > 20); + const f = &pane.file.?; + const shown = File.shownRows(tab, pane); + // Rows with a label: the body's first and its last among them. + var labelled: [2]bool = .{ false, false }; + for (pane.jump.items) |r| { + const at = @min(r.anchor, r.head); + const line = std.mem.count(u8, f.content[0..at], "\n"); + const col = at - File.lineStart(p.gpa, f, line); + // The row that shows its first byte is in the body, at or after + // that row's start (no row above the top). + const row = pane.wrapRow(tab, @intCast(line), @intCast(col)); + try std.testing.expect(row.row >= pane.context_rows and row.row < pane.context_rows + shown); + try std.testing.expect(col >= row.at); + if (row.row == pane.context_rows) labelled[0] = true; + if (row.row == pane.context_rows + shown - 1) labelled[1] = true; + } + try std.testing.expectEqual([2]bool{ true, true }, labelled); +} + test "flat text movement and selection replay need no scratch rows" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 12 }); -- cgit v1.3