summaryrefslogtreecommitdiff
path: root/core/views.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/views.zig')
-rw-r--r--core/views.zig40
1 files changed, 40 insertions, 0 deletions
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 });