diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/ninep/ctl.zig | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index 6d78bc44..c99ec9ab 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -29,18 +29,27 @@ const E = tree.E; // ---- which panes a command made or touched ---- +/// The serial of the pane in each slot, 0 for none. const Serials = struct { - list: [MAX_PANES]u32 = undefined, - len: usize = 0, + of: [MAX_PANES]u32 = @splat(0), fn snapshot(p: *Pardes) Serials { var s: Serials = .{}; - for (p.panes) |slot| if (slot) |pane| { - s.list[s.len] = pane.serial; - s.len += 1; + for (p.panes, &s.of) |slot, *serial| if (slot) |pane| { + serial.* = pane.serial; }; return s; } + + /// Whether the pane in slot `id` was made since the snapshot: it is in + /// a slot that held no pane or another, as a file made in an untouched + /// +New's place is under the +New's number (layout.takePane), and it + /// is not closing at the step's end, as that +New is under the number + /// it was given (Pardes.unplaced). + fn made(s: *const Serials, p: *const Pardes, id: usize) bool { + const pane = p.panes[id] orelse return false; + return pane.serial != s.of[id] and !p.unplaced.isSet(id); + } }; fn noteResult(p: *Pardes, serial: u32) void { @@ -89,14 +98,14 @@ pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) vo }; // A look that found nothing answers nothing, not the pane before it. if (!exec and p.look_missed) return; - const after = Serials.snapshot(p); var created = false; - for (after.list[0..after.len]) |serial| if (std.mem.indexOfScalar(u32, before.list[0..before.len], serial) == null) { + for (0..MAX_PANES) |k| if (before.made(p, k)) { + const made = p.panes[k].?; // A query pane's +Preview is its query pane's: that answers. - if (p.paneBySerial(serial)) |made| if (p.panes[made].?.file) |f| if (f.output) |o| if (o.from == .preview) continue; + if (made.file) |f| if (f.output) |o| if (o.from == .preview) continue; // A look that made a +Search pane (a terminal's word) // answers it: that is where the places it found are. - noteResult(p, serial); + noteResult(p, made.serial); created = true; }; if (created) return; @@ -598,10 +607,9 @@ pub fn runBuiltin(p: *Pardes, req: Req, id: usize, line: []const u8) ?Reply { const context = if (p.panes[id]) |pane| pane.serial else 0; const before = Serials.snapshot(p); _ = exec_line.executeBuiltinLine(p, id, line); - const after = Serials.snapshot(p); var created = false; - for (after.list[0..after.len]) |serial| if (std.mem.indexOfScalar(u32, before.list[0..before.len], serial) == null) { - noteResult(p, serial); + for (0..MAX_PANES) |k| if (before.made(p, k)) { + noteResult(p, p.panes[k].?.serial); created = true; }; if (!created) noteResult(p, context); |
