summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig18
1 files changed, 11 insertions, 7 deletions
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`,