summaryrefslogtreecommitdiff
path: root/core/panes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/panes.zig')
-rw-r--r--core/panes.zig75
1 files changed, 29 insertions, 46 deletions
diff --git a/core/panes.zig b/core/panes.zig
index 02ee805f..8939bd05 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -31,12 +31,22 @@ pub const Pane = struct {
/// it (views.zig). (The 9P server's part of `fs` says so in its type.)
pub const replica = .{
.local = .{ "pv", "pv_known" },
- .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "notices", "pan" },
+ .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "top_skip", "notices", "pan" },
.len = .{ .{ "msg", "msg_len" }, .{ "msg_older", "msg_older_len" }, .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } },
// A picture's memory is its own allocator's (a dump loaded makes
// it there).
.alloc = .{ .{ "addon", "image" }, .{ "pdf", "image" }, .{ "terminal", "terminal" } },
+ // Slots of the session's (walk.zig `.index`): a view's, a pane's,
+ // each looked at before it is used (one gone since is no error).
+ .index = .{ .{ "sized_by", Pardes, "views" }, .{ "prompt_view", Pardes, "views" }, .{ "search_pane", Pardes, "panes" } },
+ // The tag's prefix as it was placed: one its room holds.
+ .place = .{.{ "tag_lead", "leadRoom" }},
};
+ /// The room a tag's computed prefix is made in, each step (Pardes.sync).
+ pub const prefix_room = 32 * 1024;
+ pub fn leadRoom(_: *const Pane) usize {
+ return prefix_room;
+ }
/// A pane's slot in `Pardes.panes`, as it crosses the core's edge: an
/// entry's argument or answer, an event's, an effect's, a host call's.
/// A type of its own, so a view's slot (`View.Id`) is not taken for
@@ -309,6 +319,12 @@ pub const Pane = struct {
wrap_n: u16 = 0,
/// A row map also exists for sticky headers when soft wrapping is off.
body_wrapped: bool = false,
+ /// Where the view's top is inside its line's rows (File.Top) for the
+ /// geometry of `key`: the row it is and the bytes of the line before
+ /// it, found by the geometry's walk or by the step that put the top
+ /// there; read only through File.topSkip, which walks one of another
+ /// key again (another view's top, a step's for the next geometry).
+ top_skip: struct { key: u64 = 0, row: u32 = 0, at: usize = 0 } = .{},
context_rows: u16 = 0,
body_rows: u16 = 0,
body_visible_rows: u16 = 0,
@@ -636,15 +652,11 @@ pub const Pane = struct {
return .{ .row = -1, .at = 0 };
}
- pub fn scrollBy(pane: *Pane, delta: i32) void {
- if (pane.file) |*f| {
- const max: i64 = @intCast(File.nlines(pane.gpa, f) -| 1);
- const n = std.math.clamp(@as(i64, @intCast(f.scroll)) + delta, 0, max);
- const next: usize = @intCast(n);
- if (next != f.scroll) {
- f.scroll = next;
- f.syntax_dirty = true;
- }
+ /// The view moved `delta` rows: a file's through its lines' wrapped
+ /// rows (File.Top), a terminal's through its history.
+ pub fn scrollBy(pane: *Pane, tab: u16, delta: i32) void {
+ if (pane.file != null) {
+ _ = File.scrollRows(tab, pane, delta);
} else if (pane.addon == null) {
// the vt scrolls in SHELL rows; convert through the edit buffer.
// The alternate screen has no history (ghostty's scrolls none):
@@ -668,43 +680,14 @@ pub const Pane = struct {
}
pub fn ensureCursorVisible(pane: *Pane, tab: u16) void {
- File.geometry(tab, pane);
- const off = pane.scroll();
- var in_context = false;
- // The map is the view's as it is now (File.geometry): an ancestor is
- // pinned only in the view it was found for.
- if (pane.context_rows < pane.wrap_n and pane.wrap_line[pane.context_rows] == off) {
- for (pane.wrap_line[0..pane.context_rows]) |row| {
- if (row == pane.body.cur_row) {
- in_context = true;
- break;
- }
- }
- }
- // Scrolloff is measured in the ordinary body, excluding sticky rows.
- var margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, pane.rows) - 1, 2));
- var last = off + @as(i32, pane.rows) - 1;
- const visible_rows = if (pane.body_visible_rows > 0) @min(pane.wrap_n, pane.body_visible_rows) else pane.wrap_n;
- if (pane.context_rows < visible_rows) {
- const lines_shown = pane.wrap_line[visible_rows - 1] - pane.wrap_line[pane.context_rows];
- last = off + lines_shown;
- margin = @min(margin, @divTrunc(@max(0, lines_shown), 2));
- }
- if (!in_context) {
- if (pane.follow_edges != 0 and (pane.body.cur_row < off or pane.body.cur_row > last)) pane.follow_crossed = true;
+ if (pane.file != null) File.show(tab, pane, pane.body.cur_row, pane.body.cur_col, config.scroll_off) else {
+ // A terminal's rows are its lines.
+ const off = pane.scroll();
+ const margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, pane.rows) - 1, 2));
+ const last = off + @as(i32, pane.rows) - 1;
if (pane.body.cur_row < off + margin) {
- if (pane.follow_edges & 1 == 0) pane.scrollBy(pane.body.cur_row - margin - off);
- } else if (pane.body.cur_row > last - margin and pane.follow_edges & 2 == 0) {
- var to = pane.body.cur_row + margin;
- if (pane.file) |*f| {
- // The margin only reveals text: a pane its whole text
- // fits in never scrolls for it. A longer one keeps
- // helix's clamp at the buffer's last line.
- const lines: i32 = @intCast(File.nlines(pane.gpa, f));
- to = @min(to, if (off == 0 and pane.textFits()) @max(pane.body.cur_row, lines - 1 - @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) else lines - 1);
- }
- pane.scrollBy(@max(0, to - last));
- }
+ pane.scrollBy(tab, pane.body.cur_row - margin - off);
+ } else if (pane.body.cur_row > last - margin) pane.scrollBy(tab, pane.body.cur_row + margin - last);
}
if (pane.file) |f| {
if (pane.body_wrapped) return;