summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/File.zig b/core/File.zig
index b2439b29..8b7adae3 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -2095,6 +2095,23 @@ pub fn textRowLine(tab: u16, pane: *Pane, from: i64, margin: i64, way: enum { do
return null;
}
+pub const Bytes = struct { start: usize, end: usize };
+
+/// The bytes of the text `pane`'s body shows: its first row's first to its
+/// last row's last (whole lines unwrapped, as each row is one).
+pub fn shownBytes(tab: u16, pane: *Pane) Bytes {
+ const f = &pane.file.?;
+ const shown = shownRows(tab, pane);
+ if (!pane.body_wrapped) return .{ .start = lineStart(pane.gpa, f, f.scroll), .end = lineStart(pane.gpa, f, f.scroll + shown) };
+ const first = pane.context_rows;
+ const last = first + shown - 1;
+ const start = lineStart(pane.gpa, f, @intCast(pane.wrap_line[first])) + @as(usize, @intCast(pane.wrap_col[first]));
+ const line: usize = @intCast(pane.wrap_line[last]);
+ if (line >= nlines(pane.gpa, f)) return .{ .start = start, .end = f.content.len };
+ const text = sourceLine(pane, @intCast(line));
+ return .{ .start = start, .end = lineStart(pane.gpa, f, line) + fitEnd(tab, text, @intCast(pane.wrap_col[last]), wrapWidth(pane, pane.view.wrap) -| pane.wrap_pad[last]) };
+}
+
/// A call stack's row after its line's first starts with its tree's guide
/// (locations.treeContinuation), in `buffer`; any other row with none.
fn guideOf(f: *const State, text: []const u8, at: usize, width: usize, buffer: *[1024]u8) []const u8 {