summaryrefslogtreecommitdiff
path: root/core/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/look.zig')
-rw-r--r--core/look.zig34
1 files changed, 32 insertions, 2 deletions
diff --git a/core/look.zig b/core/look.zig
index 21043250..f9dcfbc3 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -803,7 +803,7 @@ pub fn advanceLookHover(p: *Pardes) void {
p.look_hover_wait = null;
}
-pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center, keep }) void {
+pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center, third, keep }) void {
if (id >= MAX_PANES) return;
const pane = p.panes[id] orelse return;
p.view().active = id;
@@ -822,7 +822,9 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center,
if (at.line > panes.File.nlines(p.gpa, f)) return;
// centred (its first row of text half the body's rows down, as
// zz), clamped at the top; a text that fits is shown whole
- if (landing == .center) panes.File.setTop(pane, if (pane.textFits()) .{ .line = 0 } else panes.File.walkRows(p.settings.tab, pane, .{ .line = at.line - 1, .row = panes.File.rowOf(p.settings.tab, pane, at.line - 1, 0) }, -@as(i64, pane.rows / 2)).to);
+ // or a third of them down (a picker's preview, UX D7: context above
+ // its landing line, the rest below)
+ if (landing != .keep) panes.File.setTop(pane, if (pane.textFits()) .{ .line = 0 } else panes.File.walkRows(p.settings.tab, pane, .{ .line = at.line - 1, .row = panes.File.rowOf(p.settings.tab, pane, at.line - 1, 0) }, -@as(i64, if (landing == .third) (pane.rows + 2) / 3 else pane.rows / 2)).to);
}
pane.body.cur_row = std.math.cast(i32, at.line - 1) orelse return;
pane.body.cur_col = columnOn(pane, pane.body.cur_row, at.col);
@@ -1609,6 +1611,9 @@ fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
const v = p.view();
const pane = p.panes[id] orelse return;
+ // A question's answer word on the pane it waits on, Looked at (a click,
+ // B3 on `Reload` in its tag): answered, as Exec answers it.
+ if (pardes.Messages.answerWord(p, id, operand_raw)) return;
// `~/x`, `~/x:12`, `~/x:/re/`: home, before anything reads the text.
// Anything else as written: a look of ` return x` is of those blanks
// too (the path, address and command readings below trim for
@@ -2960,3 +2965,28 @@ test "Plumb: a commit hash looked at in a git work tree is git show's, paged; ou
};
try std.testing.expect(paged);
}
+
+test "a Look at a question's answer word in its pane answers it, as an Exec does: B3 on Reload reads the file again" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 });
+ defer p.deinit();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = "one\n" });
+ var dir: [4096]u8 = undefined;
+ const path = try std.fmt.allocPrint(std.testing.allocator, "{s}/c.zig", .{dir[0..try tmp.dir.realPath(std.testing.io, &dir)]});
+ defer std.testing.allocator.free(path);
+ const pane = try p.setTestFile("one\n");
+ const id = p.view().active;
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try p.gpa.dupe(u8, path);
+ pane.file.?.saved_hash = panes.File.fileHash(&pane.file.?);
+ for ([_]u21{ 'G', 'o', 't', 'w', 'o', Key.escape }) |cp| p.update(.{ .key = .{ .cp = cp } });
+ const disk = "zero\none\n";
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = disk });
+ p.update(.{ .file_changed = .{ .pane = .at(id), .bytes = disk } });
+ try std.testing.expect(p.messages.waiting(pane) != null);
+ lookAt(p, id, "Reload");
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.messages.waiting(pane) == null);
+ try std.testing.expectEqualStrings(disk, p.panes[id].?.file.?.content);
+}