summaryrefslogtreecommitdiff
path: root/core/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/look.zig')
-rw-r--r--core/look.zig37
1 files changed, 34 insertions, 3 deletions
diff --git a/core/look.zig b/core/look.zig
index f60b90f5..eee808cb 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -1605,11 +1605,13 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// miss of its line too.
if (p.fs.failures != failures) return;
layout.compute(p);
- nt.file.?.scroll -|= @max(1, v.rects[free].h -| BOX_H) / 2;
+ // Its line half the body's rows down, a wrapped line's
+ // rows above it counted.
+ const centered = panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, @max(1, v.rects[free].h -| BOX_H) / 2)).to;
+ panes.File.setTop(nt, centered);
if (target.at.end_line != 0) {
- const centered = nt.file.?.scroll;
selectSpan(p, nt, target.at);
- nt.file.?.scroll = centered;
+ panes.File.setTop(nt, centered);
}
opened = free;
}
@@ -1840,6 +1842,35 @@ test "lookableLineSpan prefers the longest run, so a blank inside a path is one
);
}
+test "a Look that opens a file in a pane of its own puts its line half the body's rows down, a wrapped line's rows above it counted" {
+ const gpa = std.testing.allocator;
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // Line 10 of 600 bytes, eleven rows or more in a pane 60 wide.
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (0..60) |i| if (i == 10) {
+ try text.appendNTimes(gpa, 'a', 600);
+ try text.append(gpa, '\n');
+ } else try text.print(gpa, "line {d:0>2}\n", .{i});
+ try tmp.dir.writeFile(io, .{ .sub_path = "c.txt", .data = text.items });
+ 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;
+ _ = try p.setTestFile("x\n");
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/c.txt:14", .{dir}) });
+ const id = p.view().active;
+ const pane = p.panes[id].?;
+ try std.testing.expect(panes.File.lineRows(p.settings.tab, pane, 10) >= 11);
+ try std.testing.expectEqual(@as(i32, 13), pane.body.cur_row);
+ const half: i64 = @max(1, p.view().rects[id].h -| BOX_H) / 2;
+ try std.testing.expectEqual(half, panes.File.rowsTo(p.settings.tab, pane, panes.File.top(p.settings.tab, pane), 13, 100).?);
+}
+
test "a miss names a long path by its start and its end, its middle given up to …" {
var cut: [miss_path_cap + "…".len]u8 = undefined;
const long = "/home/someone/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "the-file.zig";