diff options
| -rw-r--r-- | core/TagState.zig | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/core/TagState.zig b/core/TagState.zig index 761eec48..e8ba816e 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -734,13 +734,20 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { }; level = level[0..n]; } + // Its hints on its last row, by the right block's rule (UX D3): a + // level that wraps gives them its spare row, its last child going to + // it to leave them room; a level of one row or of all its rows keeps + // its rows, and they drop where they do not fit. + const hint = "↓ unroll · ? help"; + const hinted = 2 + panes.File.displayWidth(tab, hint); var rows: usize = 1; for (level, 0..) |c, i| { const label = if (registers) try bindings.registerShown(arena, tab, bindings.registerValue(p, c.key)) else c.label; const cut = c.group or (c.more and !registers); const w = panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, label) + @intFromBool(cut); var gap: usize = if (i == 0) 1 else 2; - if (b.col() + gap + w + more(level.len - i - 1, rows == most) + (if (rows == most) struck else 0) > b.width and rows < most and b.col() > indent) { + const last: usize = if (i + 1 == level.len and rows > 1) struck + hinted else 0; + if (b.col() + gap + w + more(level.len - i - 1, rows == most) + (if (rows == most) struck else last) > b.width and rows < most and b.col() > indent) { try b.row(indent); rows += 1; gap = 0; @@ -767,9 +774,8 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { if (b.col() + struck > b.width and rows < most) try b.row(indent) else try b.put(" "); try b.styled(bindings.keyName(s.miss), .strike); } - // Its hints on its last row, by the right block's rule (UX D3). const hints = b.text.items.len; - try b.styled("↓ unroll · ? help", .dim); + try b.styled(hint, .dim); try b.right(hints, hints); return b.done(); } @@ -1364,3 +1370,23 @@ test "a click that gives the keyboard to another pane ends a level as Esc does; click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H); try std.testing.expect(p.view().tag_state.kind == .rest and hostOf(p) == null); } + +test "a rolled level that wraps has its hints on its last row at every width that leaves it a row to spare: `]` and `g` as SPC (UX D3)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + _ = try p.setTestFile("one\n"); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + for (" ]g") |root| for (40..161) |cols| { + p.update(.{ .resize = .{ .cols = @intCast(cols), .rows = 40 } }); + p.update(.{ .key = .{ .cp = root } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + try std.testing.expect(hostOf(p) != null); + const tag = try testTag(p, a); + if (std.mem.count(u8, tag, "\n") == 1) try std.testing.expect(std.mem.endsWith(u8, tag, " ↓ unroll · ? help")); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(hostOf(p) == null); + }; +} |
