diff options
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index a26cbad9..3fef1842 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -190,18 +190,14 @@ pub const LoggedMessage = struct { } }; -/// `SPC` plus the chord keys typed so far, spaced out the way the help -/// index spells a leader path. -fn leaderText(p: *const Pardes, buf: *[16]u8) []const u8 { - buf.* = @splat(' '); - @memcpy(buf[0..3], "SPC"); - var end: usize = 3; - for (p.view().leader_keys[0..p.view().leader_n]) |ch| { - if (end + 2 > buf.len) break; - buf[end + 1] = ch; - end += 2; - } - return buf[0..end]; +/// The room the leader band's line takes (TagState.lastUsed): a leaf's +/// key, word and summary (builtins.summary_max), and "(last used here)". +pub const leader_room = 192; + +/// The leaf the current which-key level ran last, and what it does: the +/// line under a rolled level (walk UI SPEC ยง3.7). +fn leaderText(p: *const Pardes, buf: *[leader_room]u8) []const u8 { + return pardes.TagState.lastUsed(p, p.view(), buf) orelse ""; } pub const Message = struct { @@ -748,7 +744,7 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row { /// What notice band `i` says. The grid pass and the band layers both /// read it here, so a terminal and a pixel shell show the same line. -pub fn noticeText(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[16]u8) []const u8 { +pub fn noticeText(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[leader_room]u8) []const u8 { return switch (pane.notices.kinds[i]) { .leader => leaderText(p, leader_buf), .prompt => pane.promptText() orelse "", @@ -929,7 +925,7 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { // draws, and a chip narrower than its text there would clip it. const tx = r.x + config.GUTTER; const tw = r.w -| config.GUTTER; - var leader_buf: [16]u8 = undefined; + var leader_buf: [leader_room]u8 = undefined; for (0..pane.notices.len) |i| { const chip = panes.File.displayWidth(p.settings.tab, noticeText(p, pane, i, &leader_buf)) + 2; pane.notices.left[i] = if (tw == 0) std.math.maxInt(u16) else tx + tw - @as(u16, @intCast(@min(chip, tw))); @@ -942,7 +938,8 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_rows: u16, r: Rect, id: usize) Pane.Notices { var n: Pane.Notices = .{}; if (r.w <= config.GUTTER or r.h <= tag_rows) return n; - if (id == v.active and v.prefix == .leader) n.push(.leader); + var used_buf: [leader_room]u8 = undefined; + if (id == v.active and pardes.TagState.lastUsed(p, v, &used_buf) != null) n.push(.leader); // Del's question shows once its delay is up: answered before that, it // was never there. const del_waiting = pane.prompt == .del_side and pane.question_due_ns > p.clock.now_ns; |
