diff options
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index f6c0a09c..cae3a0ab 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -2073,14 +2073,19 @@ pub const Pardes = struct { pane.tag_col = @intCast(pane.tag_tail.items.len); } - /// Enter on a `/` input: run `grep -nH '<pat>' <path>` in a shell in the - /// file's directory (the same path middle-click send takes), so the - /// results are ordinary persistent terminal text. Remember the results - /// pane and start n/N below its current prompt row. + /// Enter on a `/` input: peel the typed pattern off the tag tail (past the + /// " /" marker) and run it through the shared search. fn submitSearch(p: *Pardes, pane: *Pane) void { - const f = pane.file orelse return; const tail = pane.tag_tail.items; - const pat = std.mem.trim(u8, tail[@min(@as(usize, pane.search_at) + 2, tail.len)..], " \t\r\n"); + p.runSearch(pane, tail[@min(@as(usize, pane.search_at) + 2, tail.len)..]); + } + + /// grep `pat_raw` (the `/` input, or a right-click word/selection) into a + /// shell in the file's directory and arm n/N to walk the results below the + /// prompt row — the shared body of `/`-submit and file-pane right-click. + fn runSearch(p: *Pardes, pane: *Pane, pat_raw: []const u8) void { + const f = pane.file orelse return; + const pat = std.mem.trim(u8, pat_raw, " \t\r\n"); if (pat.len == 0) return; const arena = p.scratch.allocator(); var cmd: std.ArrayList(u8) = .empty; @@ -4300,7 +4305,12 @@ pub const Pardes = struct { } } switch (look.resolve(txt, cwd, &realbuf)) { - .none => {}, + // acme button-3: a word that names no file/dir, in a text file, + // is a search — grep it into a shell exactly like `/` (n/N then + // walk the results). Paths (src/a/b.rs:100) still resolve above + // and open; only the non-file case falls through here. On a + // terminal a dead look stays inert. + .none => if (pane.file != null) p.runSearch(pane, txt), .url => |u| if (u.len <= 256) p.emit(.{ .open_link = .from(u) }), .dir => |dir| { // focus an existing terminal on this dir, else fork one below |
