diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Pick.zig | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index 10c80dfc..3e326bb4 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -120,8 +120,9 @@ aside: ?File.State = null, aside_row: i32 = 0, aside_col: i32 = 0, aside_top: usize = 0, -/// The row the preview shows (`no_row`: none yet); asked again on the -/// frame after the cursor moves, never on the key that moved it. +/// What the row the preview shows is (`idOf`; `no_row`: none yet): asked +/// again on the frame after the cursor moves to another, never on the key +/// that moved it, and on the frame a row first comes under it. shown: u32 = no_row, /// The preview on (M-p). previews: bool = true, @@ -437,7 +438,8 @@ pub fn produceAll(p: *Pardes, tick: bool) void { /// The frames a live picker still owes: scoring, a preview (nextWake's). pub fn busy(p: *const Pardes) bool { for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) { - if (pk.names.busy() or (pk.previews and pk.shown != p.view().tag_state.rows.at)) return true; + const at = p.view().tag_state.rows.at; + if (pk.names.busy() or (pk.previews and at < count(p, pk) and pk.shown != idOf(pk, at))) return true; }; return false; } @@ -764,7 +766,7 @@ pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usi // edit on the Changes grounds are their previews. if (!pk.previews or pk.landing != pane.serial or pk.source == .themes or pk.source == .actions) return null; const s = &p.view().tag_state; - if (pk.shown != s.rows.at or count(p, pk) == 0) return null; + if (s.rows.at >= count(p, pk) or pk.shown != idOf(pk, s.rows.at)) return null; const row = rowAt(p, pk, arena, s.rows.at) catch return null; const place = switch (row.target) { .place => |t| t, @@ -802,9 +804,11 @@ pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize { /// open pane shows is taken from it; any other is read. fn preview(p: *Pardes, pk: *Pick) void { const s = &p.view().tag_state; - if (pk.shown == s.rows.at or !pk.previews) return; - pk.shown = s.rows.at; - if (count(p, pk) == 0) return; + // No row yet: none shown, so the first to come is (a Find's listing + // and a Grep's lines come frames after the field asked). + if (!pk.previews or s.rows.at >= count(p, pk)) return; + if (pk.shown == idOf(pk, s.rows.at)) return; + pk.shown = idOf(pk, s.rows.at); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); const row = rowAt(p, pk, frame.allocator(), s.rows.at) catch return; @@ -2554,3 +2558,46 @@ test "code actions: a row that cannot be applied (a command's, an edit reaching }; try std.testing.expectEqual(@as(?u16, @intCast((pane.rows + 2) / 3)), row_at); } + +test "a picker previews the row under its cursor from the frame its rows come, when a frame with none came first: a Find's listing, a Grep's lines after their pause (UX D7)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\npub fn a() void {}\n"); + defer p.gpa.free(a_path); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" }); + p.stream.engine = .walk; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + // Find, its field empty: a frame before the listing comes (a host's + // worker sends it by an input of its own, after the step that asked). + open(p, asker, .find, "", "", ""); + const reader = p.paneBySerial(live(p).?.landing).?; + produceAll(p, true); + try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?)); + // No rows: no frame owed for a preview. + try std.testing.expect(!busy(p)); + settle(p); + try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?)); + try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path); + try std.testing.expectEqual(@as(?usize, 0), landingLine(p, frame.allocator(), p.panes[reader].?)); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Grep: its lines come once the typing pauses, frames with none before. + open(p, asker, .grep, "", "", ""); + const greader = p.paneBySerial(live(p).?.landing).?; + for ("pub") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + p.update(.tick); + try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?)); + try std.testing.expect(!busy(p)); + p.clock.now_ns = p.stream.due_ns.?; + settle(p); + try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?)); + try std.testing.expectEqualStrings(a_path, p.panes[greader].?.file.?.path); + try std.testing.expectEqual(@as(?usize, 1), landingLine(p, frame.allocator(), p.panes[greader].?)); +} |
