summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/File.zig b/core/File.zig
index 8b7adae3..8e464d61 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -108,8 +108,28 @@ 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" } },
};
+ /// The last line a view's top may be at: its text's. A clean file a
+ /// slim dump left the text of (dump.zig `Slim`, read from its file
+ /// again when it is revived) has a line a byte of what it saved at most,
+ /// in the rows a view counts (`Pane.wrap_line`).
+ pub fn lastLine(f: *const State) usize {
+ if (f.content.len == 0) if (f.saved_len) |n| return @min(n, std.math.maxInt(i32));
+ 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):