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/normal.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/normal.zig')
| -rw-r--r-- | core/normal.zig | 52 |
1 files changed, 42 insertions, 10 deletions
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 |
