summaryrefslogtreecommitdiff
path: root/core/layout.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/layout.zig')
-rw-r--r--core/layout.zig35
1 files changed, 31 insertions, 4 deletions
diff --git a/core/layout.zig b/core/layout.zig
index 4c7d6afb..7fa57ee9 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -845,10 +845,14 @@ fn bodyRows(p: *const Pardes, id: usize) u16 {
fn blankRows(p: *const Pardes, id: usize) u16 {
const pane = p.panes[id].?;
const rows = bodyRows(p, id);
- const used: usize = if (pane.file) |*f|
- // The empty line after a final newline shows nothing.
- (panes.File.nlines(p.gpa, f) -| @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) -| f.scroll
- else if (pane.isTerminal())
+ const used: usize = if (pane.file) |*f| used: {
+ // The rows from the view's top to the text's end, a wrapped line's
+ // each; the empty line after a final newline shows nothing.
+ const end = panes.File.nlines(p.gpa, f) -| @intFromBool(std.mem.endsWith(u8, f.content, "\n"));
+ const top = panes.File.top(p.settings.tab, pane);
+ if (end <= top.line) break :used 0;
+ break :used @intCast(panes.File.rowsTo(p.settings.tab, pane, top, end, rows) orelse rows);
+ } else if (pane.isTerminal())
@as(usize, panes.Term.grid(pane.terminal).cursor_y) + 1
else
rows;
@@ -2158,3 +2162,26 @@ test "tiny screens keep pane space before adding a column tag" {
try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y);
_ = try p.render(p.scratch.allocator());
}
+
+test "a new pane goes below the rows a pane's text takes, a wrapped line's each counted: a pane whose few lines fill its rows keeps them all" {
+ const gpa = std.testing.allocator;
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(io, .{ .sub_path = "b.txt", .data = "other\n" });
+ var buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(io, &buf)];
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 40 });
+ defer p.deinit();
+ p.settings.wrap = true;
+ // Two lines of 400 bytes: seven rows each at this width.
+ const long = &@as([400]u8, @splat('a'));
+ const pane = try p.setTestFile(long ++ "\n" ++ long ++ "\n");
+ const a = p.view().active;
+ const used = panes.File.lineRows(p.settings.tab, pane, 0) + panes.File.lineRows(p.settings.tab, pane, 1);
+ try std.testing.expect(used >= 12);
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/b.txt", .{dir}) });
+ try std.testing.expect(p.view().active != a);
+ try std.testing.expect(p.view().rects[a].h -| pane.tag_rows >= used);
+}