diff options
| -rw-r--r-- | core/Band.zig | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/core/Band.zig b/core/Band.zig index 7d874319..cd4ca75b 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -178,8 +178,10 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band { at = i; }; const node = bindings.nodeAt(root, path); - band.add(try levelStep(arena, pane, level, at, if (node) |n| s.used[n.group] else 0)); - band.add(try docStep(p, arena, root, path, level[at])); + if (level.len > 0) { + band.add(try levelStep(arena, pane, level, at, if (node) |n| s.used[n.group] else 0)); + band.add(try docStep(p, arena, root, path, level[at])); + } try band.place(p, arena, pane, id); return band; }, @@ -212,8 +214,12 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band { for (level, 0..) |c, i| if (c.key == (if (s.hi != 0) s.hi else used)) { at = i; }; - band.add(try levelStep(arena, pane, level, at, used)); - band.add(try docStep(p, arena, cur.root, cur.path, level[at])); + // A level with no children (an addon's group, the addon gone while it + // was shown) gives no rows. + if (level.len > 0) { + band.add(try levelStep(arena, pane, level, at, used)); + band.add(try docStep(p, arena, cur.root, cur.path, level[at])); + } try band.place(p, arena, pane, id); return band; } @@ -1062,3 +1068,49 @@ test "a band is drawn in the theme's roles (UX D4): spines in the rule ink, a ch } try std.testing.expect(dimmed > 0 and why); } + +test "an empty level gives no rows: SPC unrolled on an addon's group, or describe-key on its word, the addon gone, draws and takes keys" { + 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\ntwo\n"); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + // An addon's word `SPC X a`, under a group of its own (the registry as + // Addon.take leaves it); its kind is never run here. + p.kinds.words[0] = .{ .kind = 0 }; + p.kinds.words[0].name.set("Probe"); + p.kinds.words[0].leader.set("Xa"); + p.kinds.nwords = 1; + var children: [bindings.max_children]bindings.Child = undefined; + for ([_]u21{ ' ', 'X', Key.down }) |c| p.update(.{ .key = .{ .cp = c } }); + try std.testing.expect(p.view().prefix == .leader and p.view().tag_state.unrolled); + try std.testing.expectEqualStrings("X", p.view().leader_keys[0..p.view().leader_n]); + try std.testing.expectEqual(@as(usize, 1), bindings.level(p, .leader, "X", &children).len); + _ = try p.render(a); + // The addon gone (Addon.drop) while its group is unrolled: the level + // has no children, the band no rows, and its keys pass. + p.kinds.nwords = 0; + try std.testing.expectEqual(@as(usize, 0), bindings.level(p, .leader, "X", &children).len); + _ = try p.render(a); + try std.testing.expectEqual(@as(usize, 0), (try of(p, a, p.panes[p.view().active].?, p.view().active)).?.nsteps); + for ([_]u21{ Key.down, Key.up, Key.enter, Key.backspace }) |c| { + p.update(.{ .key = .{ .cp = c } }); + _ = try p.render(a); + } + p.update(.{ .key = .{ .cp = Key.escape } }); + // describe-key found on the word, then the addon gone: its level, the + // word's group's, has no children. + p.kinds.nwords = 1; + for (" hk Xa") |c| p.update(.{ .key = .{ .cp = c } }); + try std.testing.expect(p.view().tag_state.kind == .describe and p.view().tag_state.found); + _ = try p.render(a); + p.kinds.nwords = 0; + _ = try p.render(a); + try std.testing.expectEqual(@as(usize, 0), (try of(p, a, p.panes[p.view().active].?, p.view().active)).?.nsteps); + for ([_]u21{ Key.down, Key.backspace, Key.enter }) |c| { + p.update(.{ .key = .{ .cp = c } }); + _ = try p.render(a); + } +} |
