summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Band.zig35
-rw-r--r--core/Core.zig2
-rw-r--r--core/Pick.zig42
-rw-r--r--core/layout.zig12
-rw-r--r--test/snapshots/find.golden10
-rw-r--r--test/snapshots/fsearch.golden27
-rw-r--r--test/snapshots/lsp.golden25
7 files changed, 114 insertions, 39 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 07c2f83d..e34b6a49 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -73,6 +73,8 @@ pub const max_spines = 12;
pub const min_width = 24;
/// A doc's rows, the fewest a band with one has.
const doc_rows = 4;
+/// The body rows a band leaves its pane at least: it gives way first (UX D6).
+pub const body_rows = 6;
/// A level's rows past which it flows into two columns.
const one_column = 9;
@@ -635,7 +637,35 @@ test "SPC Down unrolls the level into a band under the tag's text, the body push
try std.testing.expect(!p.view().tag_state.unrolled);
}
-test "a pane whose body would drop below four rows under its band borrows them from its column" {
+test "a band keeps its pane's body 60 % of the pane, borrowed from its column; where the column has not the rows, the band gives way before the body drops under 6" {
+ const Key = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const top = p.view().active;
+ p.newScratchBelow(top);
+ const low = p.view().active;
+ p.newScratchBelow(low);
+ p.view().active = low;
+ p.sync();
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = Key.down } });
+ const pane = p.panes[low].?;
+ const r = p.view().rects[low];
+ try std.testing.expect(pane.band_rows >= doc_rows);
+ try std.testing.expect(@as(u32, r.h -| pane.tag_rows) * 5 >= @as(u32, r.h) * 3);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // A window of 12 rows: the band shrinks, the body keeps 6.
+ p.update(.{ .resize = .{ .cols = 120, .rows = 12 } });
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = Key.down } });
+ p.sync();
+ const short = p.view().rects[low];
+ try std.testing.expect(short.h -| pane.tag_rows >= 6 or pane.band_rows == 0);
+ try std.testing.expect(pane.band_rows < Band.takes(p, low));
+}
+
+test "a pane whose body would drop below six rows under its band borrows them from its column" {
const Key = pardes.Key;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 24 });
defer p.deinit();
@@ -652,7 +682,8 @@ test "a pane whose body would drop below four rows under its band borrows them f
const pane = p.panes[low].?;
const r = p.view().rects[low];
try std.testing.expect(r.h > before);
- try std.testing.expect(r.h -| pane.tag_rows >= 4);
+ // Its body six rows at least (UX D6): a column too short for 60 %.
+ try std.testing.expect(r.h -| pane.tag_rows >= 6);
// No pane dims out of rest (UX D9): the others look as at rest.
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
diff --git a/core/Core.zig b/core/Core.zig
index 26860365..5b6eba75 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -2063,7 +2063,7 @@ pub fn sync(p: *Pardes) void {
// The band unrolled under the tag's text pushes the body down:
// the tag's rows, as everything under them counts them.
// A terminal's or a kind's is drawn over its body instead (Band.over).
- pane.band_rows = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows);
+ pane.band_rows = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows -| pardes.Band.body_rows);
pane.tag_rows += pane.band_rows;
const cols = @max(1, r.w -| config.GUTTER);
// The tag steals the top rows. The pty is what the pane shows
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();
diff --git a/core/layout.zig b/core/layout.zig
index de12294b..5550ef4a 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -1471,13 +1471,17 @@ pub fn compute(p: *Pardes) void {
/// The fewest rows a pane is laid out with: a terminal keeps its tag and
/// `min_body_rows` (a shorter one loses its prompt and reads busy for
/// ever), a text pane may shrink to its tag, as acme's windows do. A tag
-/// out of rest keeps its band and four body rows, borrowed from the
-/// column's other panes, which shrink to their tags until it rolls up
-/// (walk UI SPEC §3.6).
+/// out of rest keeps its band and a body of 60 % of the pane and 6 rows at
+/// least (UX D6), borrowed from the column's other panes, which shrink to
+/// their tags until it rolls up (walk UI SPEC §3.6).
fn floorRows(p: *Pardes, id: usize) u16 {
const pane = p.panes[id] orelse return 0;
const band = if (pardes.Band.over(pane)) 0 else pardes.Band.takes(p, id);
- if (band > 0) return @max(1, pane.tag_rows -| pane.band_rows) + band + 4;
+ if (band > 0) {
+ const above = @max(1, pane.tag_rows -| pane.band_rows) + band;
+ // A body of 60 % is one and a half times what is above it.
+ return above + @max(pardes.Band.body_rows, (3 * above + 1) / 2);
+ }
return if (pane.isTerminal()) @max(1, pane.tag_rows) + min_body_rows else 1;
}
diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden
index 6af0405d..da1b0e4e 100644
--- a/test/snapshots/find.golden
+++ b/test/snapshots/find.golden
@@ -77,7 +77,9 @@
|3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist
|4: │ │ nothing matches
|5: │ │
-|6: 1 beta body
+|6: │ │
+|7: │ │
+|8: 1 beta body
|40: ✓ /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Find 2 messages · SPC h m
== snap cancel grid=120x41 cursor=7,3
|2: here.txt:1 › Find zqm 2/3 › /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Keep Save Term Collapse Follow Del
@@ -85,10 +87,14 @@
|4:
|5:
|6:
+|7:
+|8:
== snap topbar grid=120x41 cursor=29,2
|2: ^ Find zqm 2/3 › ␣ f Find bod 0
|3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist
|4: │ │ nothing matches
|5: │ │
-|6: 1 beta body
+|6: │ │
+|7: │ │
+|8: 1 beta body
|40: ✓ /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Find ×2 2 messages · SPC h m
diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden
index fe5a29ef..905d2ef0 100644
--- a/test/snapshots/fsearch.golden
+++ b/test/snapshots/fsearch.golden
@@ -75,7 +75,19 @@
|18: g.txt │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a
|19: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b
|20: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:10:1: MARK c
-|21: 1 l1
+|21: │ │
+|22: 1 l1
+|23: 2 MARK a
+|24: 3 l3
+|25: 4 l4
+|26: 5 l5
+|27: 6 MARK b
+|28: 7 l7
+|29: 8 l8
+== snap ctrln grid=180x31 cursor=110,16
+|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3
+|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a
+|19: │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b
|22: 2 MARK a
|23: 3 l3
|24: 4 l4
@@ -84,19 +96,6 @@
|27: 7 l7
|28: 8 l8
|29: 9 l9
-== snap ctrln grid=180x31 cursor=110,16
-|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3
-|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a
-|19: │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b
-|21: 2 MARK a
-|22: 3 l3
-|23: 4 l4
-|24: 5 l5
-|25: 6 MARK b
-|26: 7 l7
-|27: 8 l8
-|28: 9 l9
-|29: 10 MARK c
== snap landed grid=180x31 cursor=97,22
|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse
|17: ls Follow Del
diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden
index 94958ba4..06127538 100644
--- a/test/snapshots/lsp.golden
+++ b/test/snapshots/lsp.golden
@@ -62,18 +62,19 @@
|4: │ │ ▶ a.zig:1:7-9 std
|5: │ │ a.zig:3:4-9 helper
|6: │ │ a.zig:7:8-11 main
-|7: 1 const std = @import("std");
-|8: 2
-|9: 3 fn helper(x: u32) u32 {
-|10: fn helper(x: u32) u32
-|11: (fn (u32) u32)
-|12: 4 return x + 1;
-|13: 5 }
-|14: 6
-|15: 7 pub fn main() void {
-|16: 8 _ = helper(41);
-|17: 9 }
-|18: ~
+|7: │ │
+|8: 1 const std = @import("std");
+|9: 2
+|10: 3 fn helper(x: u32) u32 {
+|11: fn helper(x: u32) u32
+|12: (fn (u32) u32)
+|13: 4 return x + 1;
+|14: 5 }
+|15: 6
+|16: 7 pub fn main() void {
+|17: 8 _ = helper(41);
+|18: 9 }
+|19: ~
|40: ✓ /tmp/pardes-snap/lsp/cwd/a.zig Symbols 2 messages · SPC h m
== snap step grid=120x41 cursor=27,2
|2: ^ a.zig:8 › ␣ l Symbols jn 0