diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 14:42:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 14:58:20 -0300 |
| commit | 249e0c92979012fc839ccd7b06643ee8ad5a735e (patch) | |
| tree | c487b3450079aad3d2687ec49f7309fc102e6cde | |
| parent | 8d0b21544824051873950ddcae1d4aab027a01fc (diff) | |
| download | pardes-249e0c92979012fc839ccd7b06643ee8ad5a735e.tar.gz pardes-249e0c92979012fc839ccd7b06643ee8ad5a735e.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | core/File.zig | 88 | ||||
| -rw-r--r-- | core/exec.zig | 7 | ||||
| -rw-r--r-- | core/normal.zig | 2 | ||||
| -rw-r--r-- | core/panes.zig | 3 | ||||
| -rw-r--r-- | core/root.zig | 2 |
5 files changed, 58 insertions, 44 deletions
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)" }, |
