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 +++++++++++++++++ 1 file changed, 17 insertions(+) (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 { -- cgit v1.3