summaryrefslogtreecommitdiff
path: root/core/Pick.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Pick.zig')
-rw-r--r--core/Pick.zig42
1 files changed, 38 insertions, 4 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index 52976f15..52e9601d 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -624,13 +624,18 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
return h;
}
-/// The band's rows: as many as the list will show, eleven at most, from
-/// what the source has (not what the query keeps: typing never moves the
-/// body).
+/// The band's rows (UX D6): as many as the list will show, from what the
+/// source has (not what the query keeps: typing never moves the body),
+/// four at least, eleven at most, and 40 % of the host's column at most
+/// (its panes' rows, which a borrow moves between them, never changes).
pub fn bandRows(p: *const Pardes) u16 {
const pk = live(p) orelse return 0;
const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len;
- const rows: usize = @max(1, @min(Band.Cursor.shown, have));
+ const v = p.view();
+ const at = @import("layout.zig").findPane(p, TagState.hostOf(p) orelse return 0) orelse return 0;
+ var column: usize = 0;
+ for (v.cols[at.col].panes[0..v.cols[at.col].n]) |id| column += v.rects[id].h;
+ const rows: usize = @max(1, @min(Band.Cursor.shown, @max(4, have), column * 2 / 5));
// Its second step's rows too: the sources, the acts and what they act on.
return @intCast(switch (pk.spine) {
.sources => @max(rows, spine_rows.len),
@@ -1578,6 +1583,35 @@ test "a picker's act row is one row under the spines, two cells right of the las
try std.testing.expect(h.spans[h.spans.len - 1].style == .dim);
}
+test "a picker's band is sized from its list at open, 4 rows at least, and typing never moves it" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
+ 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;\n");
+ defer p.gpa.free(a_path);
+ _ = try p.setTestFile("held\n");
+ const asker = p.view().active;
+ Trail.keep(p.panes[asker].?);
+ // In the test's directory: its two files listed.
+ 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;
+ open(p, asker, .find, "", "", "");
+ settle(p);
+ const reader = p.paneBySerial(live(p).?.landing).?;
+ p.sync();
+ const rows = p.panes[reader].?.band_rows;
+ // One or two files listed: four rows, ground under them.
+ try std.testing.expectEqual(@as(u16, 4), rows);
+ for ("zzq") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ settle(p);
+ p.sync();
+ try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?));
+ try std.testing.expectEqual(rows, p.panes[reader].?.band_rows);
+}
+
test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
defer p.deinit();