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/normal.zig | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'core/normal.zig') diff --git a/core/normal.zig b/core/normal.zig index 89fd72f6..61f8f26b 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -946,14 +946,31 @@ fn verticalMove(tab: u16, t: *Text, text: []const u8, range: modal.Selection, do t.sticky_col = @intCast(goal); } -/// Ctrl-d/u: scroll half a page AND move the cursor by the same rows +/// Ctrl-d/u: the view half the body's rows on, and the cursor where it +/// stood on the screen (inside the margins): on the line whose first row is +/// now there, the next one the way it went past a wrapped line's later +/// row, and the rows the view could not move (the text's end) further. +/// None in the body (inside a line taller than it): it stays, off the +/// view, and the view where it went. A terminal's rows are its lines: both +/// move by them. fn halfPageMove(tab: u16, t: *Text, text: []const u8, range: modal.Selection, down: bool) void { // 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 half: i32 = @max(1, @divTrunc(@as(i32, w.rows), 2)); - w.scrollBy(if (down) half else -half); - verticalMove(tab, t, text, range, down, @intCast(half), 0); + if (w.file == null) { + w.scrollBy(tab, if (down) half else -half); + return verticalMove(tab, t, text, range, down, @intCast(half), 0); + } + const body: i64 = File.shownRows(tab, w); + const margin = @min(config.scroll_off, @divTrunc(body - 1, 2)); + const from = File.top(tab, w); + const line: usize = @intCast(@max(0, t.cur_row)); + const on: i64 = if (File.rowsTo(tab, w, from, line, @intCast(body))) |d| d + File.rowOf(tab, w, line, @intCast(@max(0, t.cur_col))) else if (line < from.line) 0 else body - 1; + const moved = File.scrollRows(tab, w, if (down) half else -half); + const to = File.textRowLine(tab, w, on + (if (down) half else -half) - moved, margin, if (down) .down else .up) orelse return; + if (to == t.cur_row) return; + verticalMove(tab, t, text, range, to > t.cur_row, @abs(to - t.cur_row), 0); } /// gt/gb: view-relative rows, col 0, scrolloff clamped (helix goto_window) @@ -1235,13 +1252,28 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! // helix align_view: the cursor's row goes `above` rows down the // view, the middle of an odd one and the upper middle of an even one .view_top, .view_center, .view_bottom => if (t.what == .body) { - const above: i32 = switch (a.role) { - .view_top => 0, - .view_center => @divTrunc(@as(i32, pane.rows) - 1, 2), - else => @as(i32, pane.rows) - 1, - }; - pane.scrollBy(t.cur_row - (pane.scroll() + above)); - pane.ensureCursorVisible(p.settings.tab); + // In rows: zt shows the cursor's line from its first row, a + // line taller than the body from the cursor's. + const tab = p.settings.tab; + if (pane.file == null) { + const above: i32 = switch (a.role) { + .view_top => 0, + .view_center => @divTrunc(@as(i32, pane.rows) - 1, 2), + else => @as(i32, pane.rows) - 1, + }; + pane.scrollBy(tab, t.cur_row - (pane.scroll() + above)); + } else { + const body: i64 = File.shownRows(tab, pane); + const line: usize = @intCast(@max(0, t.cur_row)); + const row = File.rowOf(tab, pane, line, @intCast(@max(0, t.cur_col))); + const at: File.Top = .{ .line = line, .row = if (a.role == .view_top and row < body) 0 else row }; + File.setTop(pane, File.walkRows(tab, pane, at, switch (a.role) { + .view_top => 0, + .view_center => -@divTrunc(body - 1, 2), + else => -(body - 1), + }).to); + } + pane.ensureCursorVisible(tab); }, // helix align_view_middle: the cursor's column to the middle of an // unwrapped view -- 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/normal.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 From 8d0b21544824051873950ddcae1d4aab027a01fc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 14:06:54 -0300 Subject: tests: a view's top read off a geometry it is not the view of (row scroll round 4, fault 1, TESTS FIRST, each failing on the base ynxykzrt): the release soak's panic (run 18 of 24, a client's drawOne: `index out of bounds: index 41, len 38` at core/File.zig fillBody `text[from..end]`) is a view drawn after ANOTHER VIEW's step moved the top: the step's `show` hands its next geometry the top's byte (`Pane.top_skip`, keyed for the geometry after the move) while the map stays the one made before it; a view that was where the first was (a client's view opened as a copy of the live one, the same size) has that map's key, so `geometry` returns early and the text pass takes `top_skip.at`, a byte of the OTHER view's top line, with no look at its key: views.zig "a view drawn after another view's step moved the top into a long wrapped line, the two alike before it: ..." panics on the base `index out of bounds: index 1584, len 5` (a probe run first, throwaway, every top_skip read checked against the walk: made by `show`, line 10 row 22, read for line 0); a STEP takes the same stale row (`topNow`): views.zig "a view's step after another view's step moved the top, the two alike before it: it scrolls from its own top's row, as a core loaded from the session (none of its geometry) does" (PageDown in the second view: expected 12, found 14 on the base: a session that drew and a client that did not step apart); and the tab width is not in the geometry's key (a Tab zeroes `geometry_key` but not `top_skip`, whose key matches again: a row start of the old width trusted; in bounds, a wrong row; 180 such reads in one Debug soak with the probe): File.zig "a view scrolled by rows into a line of tabs, the tab width changed after a frame: its body drawn from the row the new width makes, as a core loaded from it draws it" fails on the base (rows from the 8-cell width's byte 27, the 2-cell width's is 74); and a second derived reader of the same kind, found by the table of every reader of a pane's geometry (normal.zig `gotoWindow` read `context_rows` before `shownRows` made the geometry): normal.zig "gt after a step that moved the view off the place its geometry was made for: ..." (two notches up off the held headers, then gt: expected 3, found 5 on the base: the session read the held rows of the place before the notch) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/File.zig | 28 ++++++++++++++++++ core/normal.zig | 32 ++++++++++++++++++++ core/views.zig | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) (limited to 'core/normal.zig') diff --git a/core/File.zig b/core/File.zig index 8e464d61..163f40ff 100644 --- a/core/File.zig +++ b/core/File.zig @@ -3679,3 +3679,31 @@ test "Syntax off in a patch's pane takes the language's ink and leaves the patch if (pass == 1) try std.testing.expect(differ); } } + +test "a view scrolled by rows into a line of tabs, the tab width changed after a frame: its body drawn from the row the new width makes, as a core loaded from it draws it" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); + defer p.deinit(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + try text.appendSlice(gpa, "head\n"); + for (0..40) |i| try text.print(gpa, "\tw{d}", .{i}); + try text.appendSlice(gpa, "\ntail\n"); + const pane = try p.setTestFile(text.items); + try std.testing.expect(p.executeBuiltinLine(0, "Tab 8")); + // The top on line 1's fourth row (at 8 cells a tab), drawn. + const f = &pane.file.?; + f.scroll = 1; + f.scroll_row = 3; + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + _ = try p.render(arena.allocator()); + try std.testing.expect(p.executeBuiltinLine(0, "Tab 2")); + const drawn = try bodyText(p.settings.tab, arena.allocator(), pane, f); + const bytes = try pardes.dump.dumpBytes(p); + defer gpa.free(bytes); + const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, bytes, null); + defer loaded.deinit(); + const lp = loaded.panes[0].?; + try std.testing.expectEqualStrings(try bodyText(loaded.settings.tab, arena.allocator(), lp, &lp.file.?), drawn); +} diff --git a/core/normal.zig b/core/normal.zig index fe0c729a..5a9794ee 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -1527,6 +1527,38 @@ test "gt and gb go to the row scroll_off rows in from the body's top and from it } } +test "gt after a step that moved the view off the place its geometry was made for: the row scroll_off in from the body's top under the context rows the view has now, as a core loaded from the session goes" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 16 }); + defer p.deinit(); + const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (std.mem.asBytes(&@as([30][21]u8, @splat(" // body line\n".*)))) ++ " }\n};\n"); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, "/test.zig"); + if (!File.supportsContext(pane)) return error.SkipZigTest; + pane.file.?.tree_context = true; + // The view inside the function, its two headers held over the body, + // drawn. + File.setTop(pane, .{ .line = 3 }); + p.sync(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + _ = try p.render(arena.allocator()); + try std.testing.expectEqual(@as(u16, 2), pane.context_rows); + // Two notches up: the top on the function's header, one header held + // (the geometry the second notch read was the one before it). + const rect = p.view().rects[0]; + for (0..2) |_| p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = rect.x + 10, .row = rect.y + 5 } }); + try std.testing.expectEqual(@as(usize, 1), pane.file.?.scroll); + const bytes = try pardes.dump.dumpBytes(p); + defer gpa.free(bytes); + const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 60, .rows = 16 }, bytes, null); + defer loaded.deinit(); + for ([_]*Pardes{ p, loaded }) |core| for ("gt") |k| core.update(.{ .key = .{ .cp = k, .text = &[_]u8{k} } }); + try std.testing.expectEqual(loaded.panes[0].?.body.cur_row, pane.body.cur_row); + try std.testing.expectEqual(@as(u16, 1), pane.context_rows); + try std.testing.expectEqual(pane.wrapAt(p.settings.tab, 1 + config.scroll_off).line, pane.body.cur_row); +} + 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(); diff --git a/core/views.zig b/core/views.zig index 4c020981..5ad9b749 100644 --- a/core/views.zig +++ b/core/views.zig @@ -898,6 +898,96 @@ test "a view drawn while another is live keeps its own cursors" { try testing.expectEqual(@as(u16, 1), pane.body.nsel); } +test "a view drawn after another view's step moved the top into a long wrapped line, the two alike before it: drawn from its own top, line 0, not from the row the step found in the other's line" { + const gpa = testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + // A short first line, and line 10 wrapped over more rows than the body. + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + try text.appendSlice(gpa, "short\n"); + for (1..10) |i| try text.print(gpa, "line {d}\n", .{i}); + for (0..500) |w| try text.print(gpa, "w{d:0>4} ", .{w}); + try text.appendSlice(gpa, "\nlast\n"); + const pane = try p.setTestFile(text.items); + const k = p.openView().?; + // View 0's step puts the cursor at line 10's end: the top goes into + // that line's rows, a row far past line 0's five bytes. View k is + // where view 0 was: its top line 0, its size view 0's. + pane.body.cur_row = 10; + pane.body.cur_col = @intCast(pardes.panes.File.sourceLine(pane, 10).len - 1); + pane.body.cur_pinned = true; + pane.ensureCursorVisible(p.settings.tab); + p.sync(); + try testing.expectEqual(@as(usize, 10), pane.file.?.scroll); + try testing.expect(pane.file.?.scroll_row > 0); + const Seen = struct { + short: bool = false, + fn present(ctx: ?*anyopaque, s: *const pardes.Surface) bool { + const seen: *@This() = @ptrCast(@alignCast(ctx.?)); + var row: [512]u8 = undefined; + for (0..s.rows) |y| { + var n: usize = 0; + for (s.cells[y * s.cols ..][0..s.cols]) |c| { + if (n + c.len > row.len) break; + @memcpy(row[n..][0..c.len], c.text[0..c.len]); + n += c.len; + } + if (std.mem.indexOf(u8, row[0..n], "short") != null) seen.short = true; + } + return true; + } + }; + var seen: Seen = .{}; + _ = try drawOne(p, k.index(), .{ .ctx = &seen, .f = Seen.present }); + try testing.expect(seen.short); +} + +test "a view's step after another view's step moved the top, the two alike before it: it scrolls from its own top's row, as a core loaded from the session (none of its geometry) does" { + const gpa = testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + // Line 3 wrapped over several rows, line 10 over more than the body. + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + for (0..12) |i| switch (i) { + 3, 10 => { + for (0..@as(usize, if (i == 3) 60 else 500)) |w| try text.print(gpa, "w{d:0>4} ", .{w}); + try text.append(gpa, '\n'); + }, + else => try text.print(gpa, "line {d}\n", .{i}), + }; + const pane = try p.setTestFile(text.items); + const f = &pane.file.?; + // Both views' top on line 3's third row, the cursor on it. + pane.body.cur_row = 3; + pane.body.cur_col = 150; + f.scroll = 3; + f.scroll_row = 2; + p.sync(); + const k = p.openView().?; + // View 0's step: the cursor to line 10's end, the top into its rows. + pane.body.cur_row = 10; + pane.body.cur_col = @intCast(pardes.panes.File.sourceLine(pane, 10).len - 1); + pane.body.cur_pinned = true; + pane.ensureCursorVisible(p.settings.tab); + p.sync(); + try testing.expect(f.scroll == 10 and f.scroll_row > 2); + // The session as a client joining it loads it: no geometry made. + const bytes = try pardes.dump.dumpBytes(p); + defer gpa.free(bytes); + const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, bytes, null); + defer loaded.deinit(); + // View k's PageDown in each, from line 3's third row. + for ([_]*Pardes{ p, loaded }) |core| { + core.toView(k); + core.update(.{ .key = .{ .cp = pardes.Key.page_down } }); + } + const lf = &loaded.panes[0].?.file.?; + try testing.expectEqual(lf.scroll, f.scroll); + try testing.expectEqual(lf.scroll_row, f.scroll_row); +} + test "a view not live keeps its place in a text another view edits" { const gpa = testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); -- cgit v1.3 From 249e0c92979012fc839ccd7b06643ee8ad5a735e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 14:42:48 -0300 Subject: rows: a view's top row is read off the geometry it is of, never another's (row scroll round 4, fault 1): `Pane.top_skip` (the top's row in its line and its first byte, a derived cache keyed by the geometry it is of) is read only through `File.topSkip`, the skip walk fillBody had, moved there: one keyed for another geometry is walked again, so the text pass, `topNow` (a step's top) and the map's pass all take the top of the view they draw or step: a step's `show` or `scrollRows` hands the NEXT geometry the byte it found (keyed so), and a view drawn or stepped in before that geometry is made (another view alike the first: a client's own view, drawn by `drawOne` after another client's unit moved the live one's top) took that byte for its own top line (the release soak's client panic, `index 41, len 38`); `geometry` stamps the top it found or took with the key it ends on (the walk brings tables and index up to it), so a text pass after a remade map reads it with no walk; `rowsOf` reads whether rows of the top line are above the top off the fresh map itself (its first body row starts past the line's first byte), not off the cache; the tab's width is in `geometryKey` (a Tab zeroed `geometry_key` and left `top_skip`, whose key then matched again: a row start of the old width trusted, a wrong row drawn and a step's top read wrong): the reset in exec.zig's Tab goes. The other readers of a pane's geometry, every one listed (the report's table): two read it on a step before making it: normal.zig `gotoWindow` read `context_rows` before `shownRows` made the geometry (gt/gb after a step that moved the top past its last geometry: the held rows of the place before; now read after it), and File.zig `rowTable` took its width from `body_wrapped` (the last geometry's) for j/k (`verticalMove`, which makes none): now from what that is made of, the view's `wrap`. The three tests of the change below pass (wip: gate to come) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/File.zig | 88 ++++++++++++++++++++++++++++++++++----------------------- core/exec.zig | 7 ++--- core/normal.zig | 2 +- core/panes.zig | 3 +- core/root.zig | 2 +- 5 files changed, 58 insertions(+), 44 deletions(-) (limited to 'core/normal.zig') diff --git a/core/File.zig b/core/File.zig index 163f40ff..1547756f 100644 --- a/core/File.zig +++ b/core/File.zig @@ -553,7 +553,7 @@ pub fn rowTable(pane: *const Pane, row: i32) ?*const Tables.Table { const f = if (pane.file) |*file| file else return null; if (row < 0 or f.tables.list.items.len == 0 or !f.tables.current(f)) return null; const table = f.tables.find(@intCast(row)) orelse return null; - const width = wrapWidth(pane, pane.body_wrapped); + const width = wrapWidth(pane, pane.view.wrap); if (width > 0 and table.width > width) return null; return table; } @@ -1858,14 +1858,38 @@ fn rowWalked(tab: u16, pane: *const Pane, width: usize, line: usize, col: usize, /// 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); + return topNow(tab, 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 { +fn topNow(tab: u16, pane: *Pane) Top { + const f = &pane.file.?; + return .{ .line = f.scroll, .row = if (f.scroll_row == 0) 0 else topSkip(tab, pane).row }; +} + +/// The top's row in its line (held at the line's last) and its first byte, +/// for the geometry made now: the one read of `Pane.top_skip`, a cache +/// keyed by the geometry it is of. A step that moves the top hands the +/// next geometry its byte (`show`, `scrollRows`), and a view drawn or +/// stepped in since leaves its own: one keyed for another geometry is +/// another view's top, or another place's, never this one's, and is +/// walked again here. +fn topSkip(tab: u16, pane: *Pane) @FieldType(Pane, "top_skip") { + if (pane.top_skip.key == pane.geometry_key) return pane.top_skip; const f = &pane.file.?; - return .{ .line = f.scroll, .row = if (f.scroll_row == 0) 0 else pane.top_skip.row }; + const width = wrapWidth(pane, pane.view.wrap); + const text = if (f.scroll < nlines(pane.gpa, f)) sourceLine(pane, @intCast(f.scroll)) else ""; + var guide: [1024]u8 = undefined; + var row: u32 = 0; + var at: usize = 0; + while (row < f.scroll_row and width > 0) : (row += 1) { + const end = fitEnd(tab, text, at, width - displayWidth(tab, guideOf(f, text, at, width, &guide))); + if (end >= text.len or end <= at) break; + at = end; + } + pane.top_skip = .{ .key = pane.geometry_key, .row = row, .at = at }; + return pane.top_skip; } pub fn setTop(pane: *Pane, to: Top) void { @@ -1968,8 +1992,8 @@ fn rowsWalked(tab: u16, pane: *const Pane, from: Top, line: usize, bound: u32) ? /// 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.?); +fn mapFresh(tab: u16, pane: *const Pane) bool { + return pane.wrap_n > 0 and pane.geometry_key == geometryKey(tab, pane, &pane.file.?); } /// The rows line `line` takes: counted off the map when the map is fresh @@ -1981,7 +2005,7 @@ fn rowsOf(tab: u16, pane: *const Pane, width: usize, map: *?bool, known: ?Known, if (known) |k| if (k.line == line) return k.rows; 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); + map.* = mapFresh(tab, pane); break :fresh map.*.?; })) { @@ -1990,8 +2014,9 @@ fn rowsOf(tab: u16, pane: *const Pane, width: usize, map: *?bool, known: ?Known, 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 of it above the top are not in the map: its top row + // starts past its first byte. + if (rows == 0 and i == pane.context_rows and line == f.scroll and pane.wrap_col[i] > 0) break; rows += 1; } else if (rows > 0) return rows; } @@ -2003,7 +2028,7 @@ fn rowsOf(tab: u16, pane: *const Pane, width: usize, map: *?bool, known: ?Known, /// moved. pub fn scrollRows(tab: u16, pane: *Pane, delta: i64) i64 { geometry(tab, pane); - const t = topNow(pane); + const t = topNow(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; @@ -2015,7 +2040,7 @@ pub fn scrollRows(tab: u16, pane: *Pane, delta: i64) i64 { 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]) }; + if (pane.body_wrapped) pane.top_skip = .{ .key = geometryKey(tab, pane, &pane.file.?), .row = row, .at = @intCast(pane.wrap_col[k]) }; return delta; } } @@ -2045,7 +2070,7 @@ fn shownNow(pane: *const 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 = topNow(pane); + const t = topNow(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; @@ -2069,7 +2094,7 @@ pub fn show(tab: u16, pane: *Pane, line_at: i32, col: i32, margin_rows: i64) voi 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] }; + pane.top_skip = .{ .key = geometryKey(tab, 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; @@ -2665,14 +2690,18 @@ pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane, f: *State) ![]c /// which each step sets. pub fn geometry(tab: u16, pane: *Pane) void { const f = if (pane.file) |*file| file else return; - const key = geometryKey(pane, f); + const key = geometryKey(tab, 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); + // again. The top's row it found or took is that key's too. + defer { + const made = geometryKey(tab, pane, f); + pane.top_skip.key = made; + pane.geometry_key = made; + } pane.body_rows = 0; pane.body_visible_rows = 0; pane.context_row_limit = null; @@ -2704,9 +2733,9 @@ fn mapRows(tab: u16, pane: *Pane, f: *State) usize { } /// Everything the geometry is made of, hashed: the text (its revision and -/// length), where it is scrolled, the pane's size, its tables, its context -/// declarations, the session's view. -fn geometryKey(pane: *const Pane, f: *const State) u64 { +/// length), where it is scrolled, the pane's size, the tab's width, its +/// tables, its context declarations, the session's view. +fn geometryKey(tab: u16, pane: *const Pane, f: *const State) u64 { const t = &f.tables; const facts = .{ f.revision, f.content.len, f.scroll, pane.hscroll, @@ -2715,7 +2744,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), f.scroll_row, + pane.view.rect_h, laneCells(pane) + @as(u16, pane.layers.heat), f.scroll_row, tab, }; // One hash of them laid out as words: every reader of the map asks for // this key, a hundred times a frame. @@ -2741,24 +2770,11 @@ fn fillBody(comptime layered: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State // row below asks whether it is that one. const end_slot: usize = if (total > 0 and endSlot(pane, total - 1)) total - 1 else std.math.maxInt(usize); var body_line: usize = f.scroll; - var body_at: usize = 0; + // The top line from the view's row in it (`top`): walked once a + // geometry (the map's pass), its text's pass a frame starting there. + var body_at: usize = topSkip(tab, pane).at; 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. - // 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)); - 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 = .{ .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) { if (dst) |out| out[written] = '\n'; diff --git a/core/exec.zig b/core/exec.zig index d1e1830f..2528805f 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -1057,11 +1057,8 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Settings.Setting, arg: ?[ }, } if (setting.action == .tab) { - for (p.panes, 0..) |slot, id| { - p.surface.body_layers[id].rows = 0; - const pane = slot orelse continue; - pane.geometry_key = 0; - } + // The geometry's key holds the tab's width: made again where it is read. + for (&p.surface.body_layers) |*layer| layer.rows = 0; look.cancelLookHover(p); } if (setting.action == .tagline_size and p.settings.font.tagline_percent != previous_tagline_percent) diff --git a/core/normal.zig b/core/normal.zig index 5a9794ee..1f7ce1a7 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -994,8 +994,8 @@ fn gotoWindow(tab: u16, t: *Text, text: []const u8, range: modal.Selection, whic // 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 held: i32 = w.context_rows; const lines = File.textLineCount(t, text); var last: i32 = shown - 1; while (last > 0 and w.wrapAt(tab, held + last).line >= lines) last -= 1; diff --git a/core/panes.zig b/core/panes.zig index 62814227..8939bd05 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -322,7 +322,8 @@ pub const Pane = struct { /// 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. + /// there; read only through File.topSkip, which walks one of another + /// key again (another view's top, a step's for the next geometry). top_skip: struct { key: u64 = 0, row: u32 = 0, at: usize = 0 } = .{}, context_rows: u16 = 0, body_rows: u16 = 0, diff --git a/core/root.zig b/core/root.zig index 3128f37b..63b77964 100644 --- a/core/root.zig +++ b/core/root.zig @@ -753,7 +753,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{ .{ "Core.zig", "distrusted frames tape", "Options: the client's own list, its runner's statistics, its tape" }, .{ "Event.zig", "native_image_patches", "what this process's shell can take" }, .{ "panes.zig", "pv pv_known", "the views' shares as this process parks them (views.zig)" }, - .{ "panes.zig", "wrap_line wrap_col wrap_pad wrap_n body_wrapped context_rows body_rows body_visible_rows context_row_limit geometry_key geometry_len top_skip", "File.geometry's, made by whoever asks first (a frame or a step) from everything its key hashes of the step's state; a tab change resets the key" }, + .{ "panes.zig", "wrap_line wrap_col wrap_pad wrap_n body_wrapped context_rows body_rows body_visible_rows context_row_limit geometry_key geometry_len top_skip", "File.geometry's, made by whoever asks first (a frame or a step) from everything its key hashes of the step's state (the tab's width too); top_skip, keyed by the geometry it is of, read only through File.topSkip, which walks one of another key again" }, .{ "panes.zig views.zig", "notices", "made again from the step's state at the top of update and presented, and at sync (Messages.collectNotices); a frame's are its own" }, .{ "panes.zig views.zig", "pan", "written by steps only (sync, a view unparked) from the pane and its terminal" }, .{ "File.zig", "cap line_starts line_cap widest", "the text's line index, of its bytes, and the widest line it found (an upper bound: which walk answers, never what)" }, -- cgit v1.3