summaryrefslogtreecommitdiff
path: root/src/views.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/views.zig')
-rw-r--r--src/views.zig49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/views.zig b/src/views.zig
index e3ba5b4e..c847b987 100644
--- a/src/views.zig
+++ b/src/views.zig
@@ -53,7 +53,7 @@ pub const fields = [_][:0]const u8{
/// A pane's fields that are each view's own: where it is in the view's
/// layout, which of its texts has the keyboard, how far it is scrolled, and
/// what the view's step measured of it (its tag's rows, its bands).
-const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "attached_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "notices" };
+const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "attached_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "notices", "pan" };
/// The body's: its cursor, selections and mode. Its undo stays the pane's.
const body_fields = [_][:0]const u8{ "mode", "cur_pinned", "cur_row", "cur_col", "msel", "vsel", "sels", "nsel", "select", "sticky_col", "restore_cursor", "last_edit", "reg_wait", "normal", "find_op", "find_ch" };
@@ -72,6 +72,7 @@ pub const PaneView = struct {
tag_rows: u16 = 1,
view: Pane.SessionView = .{},
notices: Pane.Notices = .{},
+ pan: u16 = 0,
body: Part(Text, &body_fields) = .{},
/// A document's scroll and size; a terminal's size is its pty's, which
/// every view shows (sized by its last typist, `Pardes.sync`).
@@ -216,6 +217,10 @@ fn unpark(p: *Pardes, k: u8) void {
};
}
layout.compute(p);
+ // Its terminals' cursors moved while it was out: each pan follows.
+ for (p.panes, 0..) |s, id| if (s) |pane| {
+ pane.pan = pardes.panes.terminal.panFor(p, pane, p.rects[id]);
+ };
}
/// The pane with the keyboard is one the live view shows: focused where its
@@ -285,6 +290,8 @@ pub fn close(p: *Pardes, k: u8) void {
if (sels.len > 0) p.gpa.free(sels);
pane.pv[k].body.sels = &.{};
pane.pv_known &= ~(@as(u8, 1) << @intCast(k));
+ // A name it was drafting goes with it.
+ if (pane.prompt == .name and pane.prompt_view == k) pane.closePrompt();
};
p.views_open &= ~(@as(u8, 1) << @intCast(k));
}
@@ -555,3 +562,43 @@ test "a view not live keeps its place in a text another view edits" {
try testing.expectEqual(scrolled + 3, pane.file.?.scroll);
try testing.expect(std.mem.startsWith(u8, pardes.panes.File.sourceLine(pane, 103), "line 101"));
}
+
+test "a terminal shown in a view shorter than it keeps its cursor in sight" {
+ const gpa = testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const id = p.active;
+ const term = p.panes[id].?;
+ const k = p.openView().?;
+ p.toView(k);
+ p.update(.{ .resize = .{ .cols = 100, .rows = 50 } });
+ p.update(.{ .key = .{ .cp = Key.right } });
+ const rows = term.rows;
+ try testing.expect(rows > 30);
+ var out: std.ArrayList(u8) = .empty;
+ defer out.deinit(gpa);
+ for (1..rows) |i| try out.print(gpa, "row-{d}\r\n", .{i});
+ try out.appendSlice(gpa, "LAST$ ");
+ p.update(.{ .output = .{ .pane = @intCast(id), .bytes = out.items } });
+ // Sized for the tall view, it fits there whole: nothing is passed over.
+ try testing.expectEqual(@as(u16, 0), term.pan);
+ p.toView(0);
+ p.sync();
+ try testing.expectEqual(rows, term.rows);
+ try testing.expect(term.pan > 0);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const s = try p.render(arena.allocator());
+ const r = p.rects[id];
+ // The cursor's row, the last, is on screen in the short view, inside
+ // the pane, and so is the line it is on.
+ const cursor = s.cursor.?;
+ try testing.expect(cursor.y >= r.y and cursor.y < r.y + r.h);
+ var row_text: std.ArrayList(u8) = .empty;
+ defer row_text.deinit(gpa);
+ for (0..s.cols) |x| try row_text.appendSlice(gpa, s.cells[@as(usize, cursor.y) * s.cols + x].grapheme());
+ try testing.expect(std.mem.indexOf(u8, row_text.items, "LAST$") != null);
+ // Back in the tall view, its top is where it was.
+ p.toView(k);
+ try testing.expectEqual(@as(u16, 0), term.pan);
+}