summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 14:42:48 -0300
committerGabriel Schneider <[email protected]>2026-11-24 14:58:20 -0300
commit249e0c92979012fc839ccd7b06643ee8ad5a735e (patch)
treec487b3450079aad3d2687ec49f7309fc102e6cde /core/File.zig
parent8d0b21544824051873950ddcae1d4aab027a01fc (diff)
downloadpardes-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
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig88
1 files changed, 52 insertions, 36 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';