diff options
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 98 |
1 files changed, 81 insertions, 17 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 2cb196f6..b821ab35 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -129,15 +129,17 @@ pub const Said = struct { text: Buf(256) = .{}, places: [max_places]Place = undefined, places_len: u8 = 0, - /// The lines that explain it, shown under its first place's line while - /// the caret is on it. + /// The lines that explain it, shown under the line it names when asked + /// (`open`). detail: [max_detail]Buf(128) = undefined, detail_len: u8 = 0, /// The serial of the pane it is about, 0 for none in particular. pane: u32 = 0, asks: Ask = .none, - /// Its detail shown under its first place's line whatever the caret - /// (a question's Diff). + /// Its detail unrolled, on request only (UX D13): K, SPC e or a Look on + /// its words on the caret's line (detailAt), shown under that line until + /// the caret leaves it (rollUp); a question's Diff under its place + /// whatever the caret, until `d` again. open: bool = false, /// How many times in a row it was said. n: u16 = 1, @@ -520,8 +522,9 @@ pub fn answer(p: *Pardes, i: usize, key: u8) bool { return true; } -/// SPC e (the Message word, SPEC §10.4), on the message the notice row -/// leads with: an error that names places lands them as a list in pane +/// SPC e (the Message word, SPEC §10.4): on a line a message names, its +/// detail not unrolled, that detail (UX D13); else on the message the +/// notice row leads with: an error that names places lands them as a list in pane /// `id`'s walk (Pick's `list`, its word `✗ <cause>` in the trail), the /// first landed on, n and N walking the rest, and the error goes (a /// +Search under the pane where jumps do not walk, or for a 9P script: @@ -529,6 +532,13 @@ pub fn answer(p: *Pardes, i: usize, key: u8) bool { /// else, or nothing, opens the history. pub fn act(p: *Pardes, id: usize) void { const m = &p.messages; + // On a line a message names, its detail not unrolled: unrolled (UX + // D13), the message kept; asked again, the walk below. + if (id < MAX_PANES) if (p.panes[id]) |pane| if (pane.focus == .body) if (detailAt(p, pane, pane.body.cur_row)) |s| if (!s.open) { + s.open = true; + p.needs_frame = true; + return; + }; const lead = m.headline() orelse return history(p, id); if (lead.kind == .question) { p.view().answering = lead.pane; @@ -949,29 +959,83 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect) void { } } -/// A message's detail under the caret's line (SPEC §10.2), as a body of -/// `body_h` rows shows it: the row of that line's last row, how many of the -/// detail's lines fit under it, the message (the first naming the line, as -/// the words after it are); only in the pane with the keyboard, in its body. -/// Bounded by the live messages' places and the rows shown. +/// A message's detail unrolled (SPEC §10.2, UX D13: on request only), as a +/// body of `body_h` rows shows it: the row of its line's last row, how many +/// of the detail's lines fit under it, the message. The line is the +/// caret's, where it was asked (the caret leaving it rolls it up), or a +/// question's place; its message the first naming it, as the words after +/// it are (firstAt). The caret passing a line never unrolls one. Only in +/// the pane with the keyboard, in its body. Bounded by the live messages' +/// places and the rows shown. pub fn detailUnder(p: *const Pardes, pane: *Pane, active: bool, body_h: u16) ?struct { row: u16, rows: u16, said: *const Said } { if (!active or pane.focus != .body or p.messages.live_len == 0) return null; const f = pane.file orelse return null; - const caret = @max(0, pane.body.cur_row); - const said = found: for (p.messages.live[0..p.messages.live_len]) |*s| { - for (s.places[0..s.places_len]) |*place| if (place.line == caret + 1 and std.mem.eql(u8, place.path.slice(), f.path)) break :found s; - } else return null; + const m = &p.messages; + const caret: u32 = @intCast(@max(0, pane.body.cur_row)); + const said, const line = found: { + if (m.firstAt(f.path, caret + 1)) |i| if (m.live[i].open) break :found .{ &m.live[i], @as(i32, @intCast(caret)) }; + for (m.live[0..m.live_len], 0..) |*s, i| if (s.open and s.kind == .question and s.places_len > 0 and std.mem.eql(u8, s.places[0].path.slice(), f.path)) + if (m.firstAt(f.path, s.places[0].line) == i) break :found .{ s, @as(i32, @intCast(s.places[0].line -| 1)) }; + return null; + }; if (said.detail_len == 0) return null; var row: u16 = 0; while (row < body_h) : (row += 1) { - if (pane.wrapAt(p.settings.tab, row).line != caret) continue; - if (row + 1 < body_h and pane.wrapAt(p.settings.tab, row + 1).line == caret) continue; + if (pane.wrapAt(p.settings.tab, row).line != line) continue; + if (row + 1 < body_h and pane.wrapAt(p.settings.tab, row + 1).line == line) continue; const k: u16 = @intCast(@min(said.detail_len, body_h - row - 1)); return if (k == 0) null else .{ .row = row, .rows = k, .said = said }; } return null; } +/// The first live message naming line `line` (1-based) of `path`: the one +/// whose words are drawn after that line (body_layer messageGhosts). +fn firstAt(m: *const Messages, path: []const u8, line: u32) ?usize { + for (m.live[0..m.live_len], 0..) |*s, i| for (s.places[0..s.places_len]) |*place| { + if (line > 0 and place.line == line and std.mem.eql(u8, place.path.slice(), path)) return i; + }; + return null; +} + +/// The message whose words line `row` (0-based) of `pane`'s file shows, +/// when it has a detail to unroll (UX D13): what K with one selection, SPC +/// e and a Look on those words ask for. Not a question's (its Diff is `d`). +pub fn detailAt(p: *Pardes, pane: *const Pane, row: i32) ?*Said { + const f = pane.file orelse return null; + if (row < 0) return null; + const s = &p.messages.live[p.messages.firstAt(f.path, @intCast(row + 1)) orelse return null]; + if (s.detail_len == 0 or s.kind == .question) return null; + return s; +} + +/// The keyboard's pane and its caret's line while a detail is unrolled on +/// request; null with none (nothing to roll up: nothing else read). +pub const Caret = struct { active: usize, row: i32 }; + +pub fn unrolledAt(p: *const Pardes) ?Caret { + const v = p.view(); + for (p.messages.live[0..p.messages.live_len]) |*s| if (s.open and s.kind != .question) { + const pane = p.panes[v.active] orelse return .{ .active = v.active, .row = -1 }; + return .{ .active = v.active, .row = pane.body.cur_row }; + }; + return null; +} + +/// After a key or a click (Core.update): the caret left its line, or the +/// keyboard went to another pane, since `was`: every detail unrolled on +/// request rolls up (UX D13: the next motion; a motion along the line, or +/// a click on the detail, which puts the caret on the line it explains, +/// keeps it), a question's Diff stays. +pub fn rollUp(p: *Pardes, was: ?Caret) void { + const before = was orelse return; + const now = unrolledAt(p) orelse return; + if (std.meta.eql(before, now)) return; + for (p.messages.live[0..p.messages.live_len]) |*s| if (s.kind != .question) { + s.open = false; + }; +} + /// The bands a pane shows over `r` below its `tag_rows`: the live view's /// each step, and any view's for its kind's facts (Kind.viewOf), made from /// what a dump keeps (the bands are derived). |
