From e77e2b16927f1cd55fa2edde44bb591c6197b2c5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 15:00:10 -0300 Subject: Band: an empty level gives no rows: Band.of drew a level's children and the child under its cursor's doc from `level[at]` with no child there when the level had none, so a band on a level whose children went while it was shown killed the session at its next frame (Z1's "not covered", the coordinator's addition: the user's rule, a session never dies of an input or an addon's fault); Z1's xxmkroru took away the one live way in (a Messages picker's Backspace unrolled `SPC h m`, a leaf's level), and an addon's group still is one: SPC unrolled on an addon's group (`SPC X` its words' first key, `X a` its word), the addon then gone (Addon.drop: its words with it), bindings.level finds no child there while Band.takes still gives the band its doc_rows; describe-key found on such a word, the addon gone, the same at the describe branch; RUN (TEST FIRST): Band.zig "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" (the registry as Addon.take leaves it, `SPC X Down` drawn, the words dropped, drawn, Down Up Enter Backspace each drawn; then `SPC h k SPC X a` found, dropped, drawn, keys): fails on M11 with `index out of bounds: index 0, len 0` at Band.zig:216 (Band.of's level, from draw.zig's render), and with the level's fix alone at Band.zig:182 (its describe branch); THE FIX (Band.of): both branches add the level's step and its doc only when the level has a child, the band placed with no step otherwise (its rows blank until a key or Esc takes it away: levelKey already passes every key on a level with none, so Down, Up, Enter and Backspace never index it); a user could hit it by unloading or reloading an addon (its words changed) while SPC showed its group unrolled or describe-key showed its word; core-test 1106/1277 (171 skipped: M11's 1105 + this test), load 1.6 to 4.6 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file 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); + } +} -- cgit v1.3