diff options
| -rw-r--r-- | src/pardes.zig | 24 | ||||
| -rw-r--r-- | test/snapshots/rsearch.golden | 124 | ||||
| -rw-r--r-- | test/snapshots/rsearch.snap | 49 |
3 files changed, 190 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 diff --git a/test/snapshots/rsearch.golden b/test/snapshots/rsearch.golden new file mode 100644 index 00000000..a54ae13e --- /dev/null +++ b/test/snapshots/rsearch.golden @@ -0,0 +1,124 @@ +== snap opened grid=120x30 cursor=7,2 +|Kill Newcol Tutor Debug Colors NextColor Crt Dump +| NOR /tmp/pardes-snap/rsearch/cwd/code.txt Save Del NOR /tmp/pardes-snap/rsearch/cwd Del +| 1 run count_x now +| 2 open sub/dep.txt:3 here code.txt sub +| 3 count_x again +| 4 pick two words +| +|╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ +| NOR /tmp/pardes-snap/rsearch/cwd Del +| +| code.txt sub +| +| +| +| code.txt +| +| NOR /tmp/pardes-snap/rsearch/cwd Del +| +| code.txt sub +| +| +| +| +| +| +| +| +| +| +| +== snap search grid=120x30 cursor=7,2 +|Kill Newcol Tutor Debug Colors NextColor Crt Dump +| NOR /tmp/pardes-snap/rsearch/cwd/code.txt Save Del NOR /tmp/pardes-snap/rsearch/cwd Del +| 1 run count_x now +| 2 open sub/dep.txt:3 here code.txt sub +| 3 count_x again +| 4 pick two words +| +| +| NOR /tmp/pardes-snap/rsearch/cwd Del +| +| +| code.txt +| +| /tmp/pardes-snap/rsearch/cwd/code.txt:1:run count_x now +| /tmp/pardes-snap/rsearch/cwd/code.txt:3:count_x again +| +| NOR /tmp/pardes-snap/rsearch/cwd Del +| +| code.txt sub +| +| +| +| +| +| +| +| +| +| +| +== snap select grid=120x30 cursor=7,2 +|Kill Newcol Tutor Debug Colors NextColor Crt Dump +| NOR /tmp/pardes-snap/rsearch/cwd/code.txt Save Del NOR /tmp/pardes-snap/rsearch/cwd Del +| 1 run count_x now +| 2 open sub/dep.txt:3 here code.txt sub +| 3 count_x again +| 4 pick two words +| +| +| NOR /tmp/pardes-snap/rsearch/cwd Del +| +| /tmp/pardes-snap/rsearch/cwd/code.txt:1:run count_x now +| /tmp/pardes-snap/rsearch/cwd/code.txt:3:count_x again +| +| +| /tmp/pardes-snap/rsearch/cwd/code.txt:4:pick two words +| +| NOR /tmp/pardes-snap/rsearch/cwd Del +| +| code.txt sub +| +| +| +| +| +| +| +| +| +| +| +== snap path-open grid=120x30 cursor=7,6 +|Kill Newcol Tutor Debug Colors NextColor Crt Dump +| NOR /tmp/pardes-snap/rsearch/cwd/code.txt Save Del NOR /tmp/pardes-snap/rsearch/cwd Del +| 1 run count_x now +|╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ code.txt sub +| NOR /tmp/pardes-snap/rsearch/cwd/sub/dep.txt Save Del +| 2 d2 +| 3 DEPTARGET +| 4 d4 +| NOR /tmp/pardes-snap/rsearch/cwd Del +| +| /tmp/pardes-snap/rsearch/cwd/code.txt:1:run count_x now +| /tmp/pardes-snap/rsearch/cwd/code.txt:3:count_x again +| +| +| /tmp/pardes-snap/rsearch/cwd/code.txt:4:pick two words +| +| NOR /tmp/pardes-snap/rsearch/cwd Del +| +| code.txt sub +| +| +| +| +| +| +| +| +| +| +| diff --git a/test/snapshots/rsearch.snap b/test/snapshots/rsearch.snap new file mode 100644 index 00000000..1b5671c1 --- /dev/null +++ b/test/snapshots/rsearch.snap @@ -0,0 +1,49 @@ +# acme button-3 in a text file = search: right-click / right-select reuse the +# `/` grep machinery. A click expands the file-ish word (look.isFileChar) and, +# when it names no file, greps it into a shell (results are ordinary terminal +# text; n/N walk them like `/`). A right-select greps the swept span verbatim. +# A real path (sub/dep.txt:3) still resolves and OPENS — expansion keeps / . : +# so paths are not broken; only the non-file case falls through to search. +dirmk sub +file sub/dep.txt d1\nd2\nDEPTARGET\nd4\nd5\nd6 +file code.txt run count_x now\nopen sub/dep.txt:3 here\ncount_x again\npick two words +start 30 120 -n 3 +wait 8000 code.txt +stable 700 20000 +# open code.txt: type the name in a shell, right-click it (ordinary look) +press left 5 8 +release left 5 8 +stable 400 5000 +key i +text code.txt +key esc +settle 700 +stable 400 5000 +press right 6 8 +release right 6 8 +wait 10000 count_x +stable 700 15000 +snap opened +# right-CLICK the identifier `count_x` (line 1, the 'n' at col 15). It names no +# file, so the click greps it: the results list both lines that contain it. +press right 15 3 +release right 15 3 +wait 10000 code.txt:1:run count_x +stable 700 15000 +snap search +# right-SELECT `pick two` (line 4, sweep cols 8..15): a multi-word span passes +# through verbatim (the space is kept), unlike a click's single-word expansion. +press right 8 6 +drag right 15 6 +release right 15 6 +wait 10000 code.txt:4:pick two +stable 700 15000 +snap select +# right-CLICK the path `sub/dep.txt:3` (line 2, col 18): isFileChar keeps / . : +# so the click expands the whole token and it RESOLVES — a look, not a search — +# opening dep.txt scrolled to line 3 (DEPTARGET). The "don't break paths" case. +press right 18 4 +release right 18 4 +wait 10000 DEPTARGET +stable 700 15000 +snap path-open |
