diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 18:00:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 18:20:56 -0300 |
| commit | b1fb4242c0ab52767df1b8e155edcf2692f37873 (patch) | |
| tree | c5e10602471c331a0d462a35072d883d65140933 /core/panes.zig | |
| parent | dde58f770995dcbc929708048a6e0f390c70f8af (diff) | |
| download | pardes-b1fb4242c0ab52767df1b8e155edcf2692f37873.tar.gz pardes-b1fb4242c0ab52767df1b8e155edcf2692f37873.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/panes.zig')
| -rw-r--r-- | core/panes.zig | 62 |
1 files changed, 17 insertions, 45 deletions
diff --git a/core/panes.zig b/core/panes.zig index 02ee805f..b238992a 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -31,7 +31,7 @@ pub const Pane = struct { /// it (views.zig). (The 9P server's part of `fs` says so in its type.) pub const replica = .{ .local = .{ "pv", "pv_known" }, - .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "notices", "pan" }, + .derived = .{ "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", "notices", "pan" }, .len = .{ .{ "msg", "msg_len" }, .{ "msg_older", "msg_older_len" }, .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } }, // A picture's memory is its own allocator's (a dump loaded makes // it there). @@ -309,6 +309,10 @@ 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 } = .{}, context_rows: u16 = 0, body_rows: u16 = 0, body_visible_rows: u16 = 0, @@ -636,15 +640,11 @@ pub const Pane = struct { return .{ .row = -1, .at = 0 }; } - pub fn scrollBy(pane: *Pane, delta: i32) void { - if (pane.file) |*f| { - const max: i64 = @intCast(File.nlines(pane.gpa, f) -| 1); - const n = std.math.clamp(@as(i64, @intCast(f.scroll)) + delta, 0, max); - const next: usize = @intCast(n); - if (next != f.scroll) { - f.scroll = next; - f.syntax_dirty = true; - } + /// The view moved `delta` rows: a file's through its lines' wrapped + /// rows (File.Top), a terminal's through its history. + pub fn scrollBy(pane: *Pane, tab: u16, delta: i32) void { + if (pane.file != null) { + _ = File.scrollRows(tab, pane, delta); } else if (pane.addon == null) { // the vt scrolls in SHELL rows; convert through the edit buffer. // The alternate screen has no history (ghostty's scrolls none): @@ -669,42 +669,14 @@ pub const Pane = struct { pub fn ensureCursorVisible(pane: *Pane, tab: u16) void { File.geometry(tab, pane); - const off = pane.scroll(); - var in_context = false; - // The map is the view's as it is now (File.geometry): an ancestor is - // pinned only in the view it was found for. - if (pane.context_rows < pane.wrap_n and pane.wrap_line[pane.context_rows] == off) { - for (pane.wrap_line[0..pane.context_rows]) |row| { - if (row == pane.body.cur_row) { - in_context = true; - break; - } - } - } - // Scrolloff is measured in the ordinary body, excluding sticky rows. - var margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, pane.rows) - 1, 2)); - var last = off + @as(i32, pane.rows) - 1; - const visible_rows = if (pane.body_visible_rows > 0) @min(pane.wrap_n, pane.body_visible_rows) else pane.wrap_n; - if (pane.context_rows < visible_rows) { - const lines_shown = pane.wrap_line[visible_rows - 1] - pane.wrap_line[pane.context_rows]; - last = off + lines_shown; - margin = @min(margin, @divTrunc(@max(0, lines_shown), 2)); - } - if (!in_context) { - if (pane.follow_edges != 0 and (pane.body.cur_row < off or pane.body.cur_row > last)) pane.follow_crossed = true; + 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(); + const margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, pane.rows) - 1, 2)); + const last = off + @as(i32, pane.rows) - 1; if (pane.body.cur_row < off + margin) { - if (pane.follow_edges & 1 == 0) pane.scrollBy(pane.body.cur_row - margin - off); - } else if (pane.body.cur_row > last - margin and pane.follow_edges & 2 == 0) { - var to = pane.body.cur_row + margin; - if (pane.file) |*f| { - // 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 buffer's last line. - const lines: i32 = @intCast(File.nlines(pane.gpa, f)); - to = @min(to, if (off == 0 and pane.textFits()) @max(pane.body.cur_row, lines - 1 - @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) else lines - 1); - } - pane.scrollBy(@max(0, to - last)); - } + pane.scrollBy(tab, pane.body.cur_row - margin - off); + } else if (pane.body.cur_row > last - margin) pane.scrollBy(tab, pane.body.cur_row + margin - last); } if (pane.file) |f| { if (pane.body_wrapped) return; |
