From f3b5bd10ceb4c4db7263739770d5e4bdb879ba75 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 14:16:32 -0300 Subject: Search converge 7/6: a script's Grep or Find that misses opens nothing, a dumped query pane restores as plain text; fs.py's Recent and canary to the query pane --- src/File.zig | 5 ++++- src/Query.zig | 18 ++++++++++++++++++ src/builtins.zig | 18 +++++++++++------- src/ninep/ctl.zig | 9 +++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/File.zig b/src/File.zig index f633cad0..24dc9318 100644 --- a/src/File.zig +++ b/src/File.zig @@ -244,7 +244,10 @@ pub fn dumpPane( .collapsed = pane.collapsed, .file = .{ .tree_context = file.tree_context, - .location_rows = try dumpLocationRows(arena, file.location_rows), + // A query pane's rows are its own (line 1 the query, gutter + // numbers), not location rows Restore reads: it comes back as + // plain text. + .location_rows = if (pane.query != null) &.{} else try dumpLocationRows(arena, file.location_rows), .path = file.path, .content_b64 = if (from_disk) "" else try dump.encodeBytes(arena, file.content), .dirty = dirty, diff --git a/src/Query.zig b/src/Query.zig index 6374ce42..a871b71e 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -1998,6 +1998,24 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); } +test "a dump holding a query pane, live or frozen, restores, the pane as plain text" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); + defer p.deinit(); + _ = try p.setTestFile("alpha one\nbeta\nalphabet\n"); + typeKeys(p, "/alpha"); + for (0..2) |_| { + const qid = queryPane(p).?; + try pardes.dump.dumpState(p); + const restored = try pardes.dump.initFromDump(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }, p.dump_out.?); + defer restored.deinit(); + const back = restored.panes[qid].?; + try std.testing.expect(back.query == null); + try std.testing.expectEqual(@as(usize, 0), back.file.?.location_rows.len); + try std.testing.expect(std.mem.startsWith(u8, back.file.?.content, "/alpha\n")); + p.update(.{ .key = .{ .cp = Key.enter } }); + } +} + test "a / query: Enter lands and freezes, the register filled, n and N step silently, a later / reuses the pane and Esc brings the frozen rows back" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); diff --git a/src/builtins.zig b/src/builtins.zig index cda962de..d2f215d7 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1720,8 +1720,9 @@ pub const Find = struct { // (SPC f f) typed into; with a word (B2, a script) listed, the // keyboard left where it was, a script told of a miss. const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); + const had = panes.Query.ofOwner(c.p, c.pane.serial) != null; panes.Query.open(c.p, c.id, .find, pat, pat.len == 0); - if (pat.len > 0) missed(c, e_search_miss_find); + if (pat.len > 0) missed(c, e_search_miss_find, had); } }; @@ -1733,19 +1734,22 @@ pub const Grep = struct { pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); + const had = panes.Query.ofOwner(c.p, c.pane.serial) != null; panes.Query.open(c.p, c.id, .grep, pat, pat.len == 0); - if (pat.len > 0) missed(c, e_search_miss_grep); + if (pat.len > 0) missed(c, e_search_miss_grep, had); } }; /// A script's Find or Grep (a 9P write runs it to its end before it -/// answers) that found nothing fails as one: the query pane stays, its -/// count 0, and the write hears `not found`. -fn missed(c: Ctx, text: []const u8) void { +/// answers) that found nothing fails as one, opening nothing: a query pane +/// it made goes as an Esc takes it, one it reused stays, its count 0; the +/// write hears `not found`. +fn missed(c: Ctx, text: []const u8, reused: bool) void { if (!c.p.fs.serving) return; const qid = panes.Query.ofOwner(c.p, c.pane.serial) orelse return; - const q = c.p.panes[qid].?.query.?; - if (q.total == 0) c.p.reportFailure(c.id, text); + if (c.p.panes[qid].?.query.?.total != 0) return; + if (!reused) panes.Query.cancel(c.p, qid); + c.p.reportFailure(c.id, text); } /// Search in a query pane under this pane, line 1 the argument (`Panes`, diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 635e03a6..258ea1ee 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -3069,6 +3069,15 @@ test "a script's Grep and Find fill the pane's one query pane, a row a line unde var after: usize = 0; for (p.panes) |slot| after += @intFromBool(slot != null); try testing.expectEqual(count, after); + // With no query pane under it, a miss leaves none: the one it made goes. + _ = wr(p, Node.of(found.serial, .ctl), "Del\n"); + var closed: usize = 0; + for (p.panes) |slot| closed += @intFromBool(slot != null); + try testing.expectEqual(E.NOENT, wr(p, Node.of(serialOf(p), .exec), "Find zzqqnomatchzz\n").errno()); + var left: usize = 0; + for (p.panes) |slot| left += @intFromBool(slot != null); + try testing.expectEqual(closed, left); + try testing.expect(panes.Query.ofOwner(p, serialOf(p)) == null); } test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" { -- cgit v1.3