summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 14:50:56 -0300
committerGabriel Schneider <[email protected]>2026-11-24 14:58:20 -0300
commit8688c01e9d3ce7524d37e2add652a6168c77880a (patch)
treea15c9a0bcee492f548a116bee8acd3ccbd53ccbd /core
parent249e0c92979012fc839ccd7b06643ee8ad5a735e (diff)
downloadpardes-8688c01e9d3ce7524d37e2add652a6168c77880a.tar.gz
pardes-8688c01e9d3ce7524d37e2add652a6168c77880a.zip
load: a view's top row is read back as the session holds it, never held to its line's bytes (row scroll round 4, fault 2: 'client 3's dump loaded as another session', once in the merge67b release soak): `File.State.scroll_row` was a `.place` held at a load to `lastRow` (the top line's bytes), but no step holds it so: an edit leaves a view's row where it was while its top line shrinks or another line becomes its top (`ParkedPlaces`, a twin's, the live pane's own), and every reader takes a row past its line's as the line's last (`top`/`topSkip`, the walks' `@min(t.row, rows - 1)`), so the SESSION holds such a row and a join's load cut it: another digest. TEST FIRST, failing on uxxwxpvt (the fault 1 fix): views.zig "a view's top on a wrapped line's third row, the line taken out by another view and the next one empty: its top row past its line's, read as its last, and the session's dump loads as the session" (the session's row 2 on an empty line, read as row 0; the loaded core's digest another); the place and `lastRow` deleted (a row of any size is read as its line's last by every reader: `topSkip`'s walk ends at the line's end; the digest and the key take it as a number); fault 1's stale `top_skip.row` read by a step (`scrollRows`' map path: a row of another view's line plus the notch) was a second road to such a row
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
-rw-r--r--core/File.zig15
-rw-r--r--core/views.zig40
2 files changed, 44 insertions, 11 deletions
diff --git a/core/File.zig b/core/File.zig
index 1547756f..07dfa52d 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -108,8 +108,10 @@ pub const State = struct {
// none of their bytes, and takes back what a speculation wrote
// (core/rollback.zig `Epoch.wrote`).
.journal = .{ "content", "line_starts" },
- // Where the view's top is, held to its text (walk.zig `.place`).
- .place = .{ .{ "scroll", "lastLine" }, .{ "scroll_row", "lastRow" } },
+ // Where the view's top is, held to its text (walk.zig `.place`);
+ // its row in that line is any (an edit leaves it past the line's
+ // rows, read as the last: `top`), as the session holds it.
+ .place = .{.{ "scroll", "lastLine" }},
};
/// The last line a view's top may be at: its text's. A clean file a
@@ -121,15 +123,6 @@ pub const State = struct {
return modal.lineCount(f.content) -| 1;
}
- /// The last row of the top's line its top may be at: a row holds a byte
- /// of it at least (its rows as wrapped are the view's, made after).
- pub fn lastRow(f: *const State) usize {
- if (f.content.len == 0) return 0;
- const at = modal.lineStartOffset(f.content, f.scroll);
- const end = std.mem.indexOfScalarPos(u8, f.content, at, '\n') orelse f.content.len;
- return end - at;
- }
-
path: []u8,
content: []u8,
/// The bytes `content`'s buffer has room for (0: as many as it holds):
diff --git a/core/views.zig b/core/views.zig
index 5ad9b749..e5f2038e 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -988,6 +988,46 @@ test "a view's step after another view's step moved the top, the two alike befor
try testing.expectEqual(lf.scroll_row, f.scroll_row);
}
+test "a view's top on a wrapped line's third row, the line taken out by another view and the next one empty: its top row past its line's, read as its last, and the session's dump loads as the session" {
+ const gpa = testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (0..30) |i| switch (i) {
+ 3 => {
+ for (0..60) |w| try text.print(gpa, "w{d:0>4} ", .{w});
+ try text.append(gpa, '\n');
+ },
+ 4 => try text.append(gpa, '\n'),
+ else => try text.print(gpa, "line {d}\n", .{i}),
+ };
+ const pane = try p.setTestFile(text.items);
+ const f = &pane.file.?;
+ // View k: its top on line 3's third row, its cursor well inside the body.
+ pane.body.cur_row = 10;
+ f.scroll = 3;
+ f.scroll_row = 2;
+ p.sync();
+ const k = p.openView().?;
+ // View 0 takes line 3 out: view k's top line is the empty one after it.
+ cursorTo(p, pane, 3);
+ typeKeys(p, "xd");
+ p.toView(k);
+ // A step of view k's own: its cursor inside the band, its top kept.
+ escape(p);
+ try testing.expectEqual(@as(usize, 3), f.scroll);
+ try testing.expectEqual(@as(usize, 0), pardes.panes.File.sourceLine(pane, 3).len);
+ try testing.expectEqual(@as(u32, 2), f.scroll_row);
+ try testing.expectEqual(pardes.panes.File.Top{ .line = 3, .row = 0 }, pardes.panes.File.top(p.settings.tab, pane));
+ // A client joining loads the session's dump as the session.
+ const bytes = try pardes.dump.dumpBytes(p);
+ defer gpa.free(bytes);
+ const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, bytes, null);
+ defer loaded.deinit();
+ try testing.expectEqual(pardes.walk.digest(Pardes, p), pardes.walk.digest(Pardes, loaded));
+}
+
test "a view not live keeps its place in a text another view edits" {
const gpa = testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });