diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/File.zig | 15 | ||||
| -rw-r--r-- | core/views.zig | 40 |
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 }); |
