diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-08 12:00:28 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-22 10:03:15 -0300 |
| commit | 13d5613b77c62c425c3a124a34c0c2528cc6251f (patch) | |
| tree | f3cbe41683ef31641ea087039db9fc3be81e141f | |
| parent | 046979b877f02a91cf52cc86b84c5619cb9363d3 (diff) | |
| download | pardes-13d5613b77c62c425c3a124a34c0c2528cc6251f.tar.gz pardes-13d5613b77c62c425c3a124a34c0c2528cc6251f.zip | |
Follow Helix search registers for n/N; keep Look navigation as named builtins
29 files changed, 473 insertions, 134 deletions
diff --git a/docs/helix-keys.md b/docs/helix-keys.md index 6249fc15..ddbab93b 100644 --- a/docs/helix-keys.md +++ b/docs/helix-keys.md @@ -48,7 +48,7 @@ at the bottom. collapse) — the checked-in helix goldens are the ground truth, verified case-by-case by `zig build hxdiff`. Motion-created ranges live in `pane.vsel` marked IMPLICIT (`vsel.explicit = false`); `v` extend mode, - `x`/`X` and `n`/`N` (the look-ring walk, `lookWalk`) set EXPLICIT ones. + `x`/`X` and search `n`/`N` set EXPLICIT ones. `d`/`c`/`y`/`~`/… act on the active selection either way — that is the point of the model. The pardes-specific chords (normal-mode Enter look / Tab execute) @@ -134,13 +134,14 @@ language-backend queries, and the shell pipe. | `Space` (normal, body) | starts the pardes LEADER: a key path runs the same builtin words used by tags and the topbar. The main groups are `f` files, `h` docs, `c` columns, `t` toggles/effects, `a` panel animations, `s` session, `j` jumps, `l` language, and `w` directional focus; `SPC ?` lists every path and `<prefix> ?` lists one group in `+Help`. Neither `Exit` (quits the editor, acme's Exit) nor `Kill` (stops the commands pardes typed into terminals, acme's Kill) has a leader path: both are the topbar's and the root `ctl`'s. The pending path appears on the active pane's transient body/message row. Esc or an unmapped key abandons it. Paths, Help rows, and dispatch are all generated from the builtin registry at comptime; the leader applies only to a BODY in normal mode because tags and tty programs own their input | pardes-specific; helix spends Space on pickers/LSP (section C), while pardes uses acme-style executable words | | `SPC y` `SPC Y` `SPC p` `SPC P` `SPC R` | helix's clipboard menu on helix's own letters: yank the selection to the system clipboard (`ClipYank`) or the PRIMARY selection alone (`ClipYankMain`), paste the system clipboard after (`ClipPaste`) / before (`ClipPasteBefore`) the selection, replace the selection with it (`ClipReplace`) | the same as `"+y`, `"+p`, `"+P`, `"+R`: register `+` (and `*`) IS the desktop's clipboard, the only register that reaches it. `SPC y` writes `+` alone, as helix's does, not the default register too. Builtins rather than bare chords because a leader path names a builtin: they land in Help's index and are executable words like every other verb. The clipboard holds one text, so N values go out joined by newlines, as helix sends them. On a tty the write is OSC 52 out and the READ is OSC 52 back, which many terminals refuse or gate — so `SPC y` works there and `SPC p` can be a no-op | out of corpus | | a paste from the OUTER terminal | one `Event.paste`, spliced in at the cursor | the tty shell enables bracketed paste and coalesces `paste_start`..`paste_end` into a single event; before that the bytes arrived as individual key presses and normal mode RAN them, which is how a pasted `d` deleted a line. The bytes deliberately never enter the yank register — clipboard and default register are separate stores in both directions | pardes-specific | -| `/` (any pane) | pardes' own plain-substring search into a `+Search` output buffer: the pattern is typed on a line of its own on the pane's notice band, Enter fills the buffer, and its rows are ordinary look targets. Enter also GOES to the first row — the buffer is focused and then the step `n` is and the look Enter is run in it (`Pardes.lookFirstHit`), so `/foo` lands on the first hit with the matched span selected. A pattern that matched nothing opens its empty buffer and moves nothing | KEEP, do not touch; not in the corpus (helix `/` is regex search). Find and Grep answer with OTHER files and deliberately do NOT jump. The stepping half is the next row | pardes-specific | -| `n` / `N` (any pane) | MOTION, not a jump: move the SELECTION to the next / previous look-able text and open NOTHING. Enter — the look chord — on what it leaves selected is what opens it | KEEP, do not touch; not in the corpus (helix's `n`/`N` walk regex search hits). What a step selects is the pane's GRAIN (`output_pane.Grain`, read in `Pardes.lookSpanIn`): in FREE TEXT — a terminal, a file, a PDF, a prose answer buffer — the largest whitespace-delimited run `look.resolve` can act on (`look.lookableSpan`, wrapper punctuation peeled off both ends), several to a line; in a RESULTS BUFFER one stop per ROW, the largest run its head resolves as (`look.lookableLineSpan`), because a row there IS one location and the words after it are the match rather than a second place to go; in a COMMAND list the whole line. The walk is a RING across PANES: every pane that has performed a Look, most recent first (`Pardes.look_src`), then the output buffers that have not, newest first, and only when both are empty the active pane. Exhausting a pane enters the next at its first (forward) / last (backward) span and the end wraps to the start, so `N` is the exact inverse of `n`. What it lands on becomes an EXPLICIT `vsel` with the cursor on its FIRST column, in the pane the walk focuses. ONE motion in every pane kind and every buffer kind — a PDF steps the `+Search` buffer its own search filled, `n` to select the row and Enter to jump. The single thing a buffer may change is that grain, and it changes it by BEING a kind of buffer rather than by a branch: `output_pane.Traits.steps` (a list of locations) makes a step take one row at a time, and `Traits.commands` makes it take the WHOLE LINE, because a command list (`Themes`/`Fonts`) holds words to run and there is no path inside `Theme gruvbox` to pick out. Tab on what `n` selected wears the theme, which is the same middle click on the row is. `]d`/`[d` are helix's diagnostic motions, a different binding, and they do still jump to each diagnostic (`docs/typ/guide.typ`, Keys) | pardes-specific | +| `/` (any pane) | pardes' own plain-substring search into a `+Search` output buffer: the pattern is typed on a line of its own on the pane's notice band, Enter fills the buffer, and its rows are ordinary look targets. Enter also goes to the first row using `Pardes.lookFirstHit`, so `/foo` lands on the first hit with the matched span selected. A pattern that matched nothing opens its empty buffer and moves nothing | kept as-is; not in the corpus (helix `/` is regex search). Find and Grep answer with other files and deliberately do not jump. `LookNext` / `LookPrev` select subsequent result rows | pardes-specific | +| `n` / `N` | next / previous regex match in the current text, using the last search register; counts repeat and ends wrap | only the primary selection is replaced; in select mode each match is added and becomes primary. Named registers work. `*` sets the pattern from selections with word boundaries, `Alt-*` without. The former Look ring is `LookNext` / `LookPrev`, `SPC j n` / `SPC j p`. The change is bookmarked `pardes-nN-helix`; its predecessor is `pardes-nN-before-helix`. PDFs retain their location-result navigation | helix-verified | + | insert: printable text | file: real edit; terminal: typed run splice | | helix-verified (file) | | insert: `Enter` | newline; keeps the current full indent levels and adds one 4-space logical tab when the text before the cursor ends in `(`, `[`, `{`, or `)` (including `})`) | plain lines match `insert_newline`; delimiter heuristic is pardes-specific | helix-verified (plain) / pardes-specific (delimiter) | | insert: `Backspace` (+ `Shift-Backspace`) | delete prev char, joins lines at col 0; in a line's leading blanks, back to the previous 4-column indent stop (a whole unit when on one; a tab still goes alone) | matches `delete_char_backward` and its dedent; `Ctrl-h` alias in B | helix-verified | | insert: `Up` `Down` `Left` `Right` | move cursor | matches helix's "not recommended" insert arrows | helix-verified | -| `gd` `gD` `gy` `gi` `gr` | LSP definition / declaration / type-definition / implementation / references. ONE answer jumps straight there; several fill `+Search`, where n/N walk and Enter opens | in-process ZLS (`src/lsp/lsp_zls.zig`), `.zig` only — on a file the backend does not speak these do nothing at all, with no error row. Ctrl+left-click is the mouse spelling of `gd` | out of corpus | +| `gd` `gD` `gy` `gi` `gr` | LSP definition / declaration / type-definition / implementation / references. One answer jumps straight there; several fill `+Search`, where `LookNext` / `LookPrev` walk and Enter opens | Ctrl+left-click is the mouse spelling of `gd`; language support depends on the configured backend | out of corpus | | `]d` `[d` / `]D` `[D` | step the diagnostics list / go to its last or first; if no list is up, asking the backend for one is part of the press | | out of corpus | | `=` | `format_selections` — writes a `- old` / `+ new` diff into `+Lsp` | deliberate divergence: the seam returns ROWS, not edits, so this SHOWS the formatting instead of applying it. Not in the corpus, so there is no waiver to name — the query leaves the core as an effect the headless harness has no shell to perform | out of corpus | | `Ctrl-o` / `Ctrl-i` | jumplist back / forward (also Mouse4 / Mouse5 in SDL, macOS and web); successful navigation clears selections in both panes and places the cursor at the saved location; raw tty forwards both to the child — the `Back` / `Forward` builtins, also on `SPC j o` / `SPC j i`, with `SPC j l` rendering the stack as a buffer; a closed file's entry stays, marked `(closed)`, and a jump to it opens the file again at its place | helix binds both keys (`jump_backward` / `jump_forward`) but to a POSITION jumplist; pardes' stack is over panes and focus, so the keys agree and the semantics do not. `Ctrl-i` and Tab are the same byte under the legacy encoding; there Tab keeps meaning execute, and the pair only separates where the host speaks the kitty keyboard protocol | pardes-specific | @@ -352,7 +353,7 @@ text. | Key(s) | Helix behavior | Reason | | --- | --- | --- | -| `?`, `*`, `Alt-*` | rsearch / selection-as-pattern | search — pardes has its own `/` (plain substring into an output buffer, kept as-is) and an `n`/`N` that SELECTS the next look-able text instead of walking match hits; helix regex search machinery not wanted | +| `?` | reverse search prompt | pardes keeps its own `/` plain substring search into an output buffer. `*`, `Alt-*` and search-repeat `n`/`N` are implemented and verified above | | `Space` mode: `f F e . b j g G ' w c C Alt-c / ?` | pickers, global search, palette | pickers and the command palette do not exist here — but the KEY is taken: pardes' own leader runs the acme builtins (section A). Two halves of helix's space mode DO exist and are in section A: the clipboard menu (`<space>y Y p P R`, helix's letters on helix's leader) and the LSP menu, moved one prefix deeper to `SPC l k/r/a/h/s/S/d/D` because `d`, `k`, `s` and `h` were already pardes' most-pressed keys | | Popup `Ctrl-u`/`Ctrl-d`, Completion menu, Signature help tables | LSP popups | LSP | | Picker table (all rows), Prompt table (all rows) | picker / prompt internals | pickers — pardes' tag line is its own one-line editor | @@ -364,7 +365,7 @@ text. | `:` | command mode | side-effects/file-ops — pardes builtins live in the tag, and `:` is bound to focusing it (section A) | | `gf` | goto file under selection | covered by pardes Enter-look | | `Ctrl-z` | suspend | pardes IS the terminal multiplexer | -| Select/extend mode section (prose) | `v` turns all motions into extenders, `n`/`N` keep selections | implemented for motions (phase 5: `pane.select` + the fixed anchor, differential-verified — see the `v` row in A); helix's search-`n`/`N` extension doesn't apply (pardes' `n`/`N` is the look-ring motion, which REPLACES the selection with the span it lands on) | +| Select/extend mode section (prose) | `v` turns all motions into extenders, `n`/`N` keep selections | implemented for motions (phase 5: `pane.select` + the fixed anchor, differential-verified — see the `v` row in A); search `n`/`N` add matches in select mode, as in helix | ## Differential testing (phase 5) @@ -421,9 +422,9 @@ Files (all in `test/hxcases/`): of the command from helix's own text there, so a later step is still tested when an earlier one misses. The goldens are `hx-harness test/hxcases/golf.jsonl`; `zig build hxgolf` runs them. - `golf-waivers.jsonl` pins the seven `reverse_golf_example` steps from `""N` - on: they walk the search register with `*`, `N` and `n`, which in pardes - are the acme look ring, by decision. All ten examples reproduce their published result in hx 25.07.1 under + `golf-waivers.jsonl` is empty: all 124 cases pass, including the + search-register steps of `reverse_golf_example`. All ten examples + reproduce their published result in hx 25.07.1 under the site's own conditions (a file of the example's language, auto-pairs on). Under the harness two do not, and their goldens are the harness's anyway, which pardes follows: `csv_to_sql` needs auto-pairs (off in the diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 89323766..55f8a4f0 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -167,7 +167,7 @@ the #word("Look") came from, then of each pane on the jump list, most recent first. #pairs( - [#key("/") `TODO` #key("Enter")], [a `+Search` of the lines holding `TODO`, the cursor on the first; #keys("n", "N") step through], + [#key("/") `TODO` #key("Enter")], [a `+Search` of the lines holding `TODO`, the cursor on the first; #keys("n", "N") select the next or previous match], [#word("Find") `conf`], [a `+Search` of the files below the pane's directory with `conf` in their names], [#word("Grep") `TODO`], [a `+Search` of the lines holding `TODO`, literally, under every pane's directory], ) @@ -213,7 +213,7 @@ is drawn as a diff, each hunk in its file's language. #btn("B3") on: A `.diff` or `.patch` looked at, and a diff paged (`git show`), opens as a `+Diff`, stacked as delta shows one: each hunk under its `path:line` -(`n`/`N` step through them, #btn("B3") opens it) and the declarations +(`Space j n`/`Space j p` step through them, #btn("B3") opens it) and the declarations around it, a `+`/`-` before each line, the words a changed line changed tinted and a line added or removed whole faintly. A mailed patch keeps its message and diffstat above. The files are found from the diff's directory @@ -241,7 +241,8 @@ refusals and `--nested` are in the reference. [#key("w") #key("d")], [select a word, delete it: motions select, edits act on the selection], [#key("x"), #key("v"), #key(";")], [select the line; extend; collapse to the cursor], [#key("s")], [a cursor per regex match; every edit acts at each], - [#key("/"), #keys("n", "N")], [substring search; step through everything #word("Look") would open, across panes], + [#key("/"), #keys("n", "N")], [substring search; repeat the search in the current text, wrapping at the ends], + [#keys("Space j n", "Space j p")], [#word("LookNext") / #word("LookPrev"): select locations across panes; #key("Enter") opens one], [#key("g l")], [line end], [`12G`], [line 12; a bare #key("G") does nothing], [#key("SPC ?")], [#word("Help"): every builtin, with its leader path and keys; `SPC w ?` only the paths under `SPC w`; #word("Tutor") (#key("SPC h t")) practises them], diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index ce2cedc8..e15faca7 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +- n/N follow Helix search registers, counts, wrapping and select mode. + `*` sets a search from the selection; `Alt-*` omits word boundaries. + The location ring remains as LookNext/LookPrev (Space j n/p). + ## 0.23 - A file a language server speaks for (by its extension) has `Def` and diff --git a/src/Registers.zig b/src/Registers.zig index d2a42434..3f2486cd 100644 --- a/src/Registers.zig +++ b/src/Registers.zig @@ -9,6 +9,7 @@ const std = @import("std"); const Registers = @This(); list: std.ArrayList(Reg) = .empty, +last_search: u21 = '/', pub const Reg = struct { name: u21, diff --git a/src/builtins.zig b/src/builtins.zig index c1424b2f..ef769b48 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -744,15 +744,15 @@ pub const Restore = struct { // so a Restore that could never happen spends no warning. if (comptime pardes.hosted) { const bytes = @import("fs.zig").readRestore(c.p.gpa, path, c.p.settings.dump_dir.get()) catch |err| { - var buf: [limits.host_path_cap + 64]u8 = undefined; - var words: [128]u8 = undefined; - const why = switch (err) { - error.FileNotFound => "no such file", - error.PermissionDenied => "permission denied", - error.IsDirectory => "a directory, not a dump", - else => pardes.Messages.errorWords(err, &words), - }; - return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: {s}", .{ path, why }) catch "Restore: cannot read the dump"); + var buf: [limits.host_path_cap + 64]u8 = undefined; + var words: [128]u8 = undefined; + const why = switch (err) { + error.FileNotFound => "no such file", + error.PermissionDenied => "permission denied", + error.IsDirectory => "a directory, not a dump", + else => pardes.Messages.errorWords(err, &words), + }; + return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: {s}", .{ path, why }) catch "Restore: cannot read the dump"); }; defer c.p.gpa.free(bytes); // Nor does a file that is not a dump, before any warning. @@ -1837,6 +1837,20 @@ pub const Forward = struct { } }; +/// Select the next Look location across panes; Enter opens it. +pub const LookNext = struct { + pub fn run(c: Ctx) void { + look.lookWalk(c.p, 1); + } +}; + +/// Select the previous Look location across panes; Enter opens it. +pub const LookPrev = struct { + pub fn run(c: Ctx) void { + look.lookWalk(c.p, -1); + } +}; + /// Go back to the last place jumped from in another pane. pub const Last = struct { pub fn run(c: Ctx) void { diff --git a/src/config.zig b/src/config.zig index c2f51b36..fb34b746 100644 --- a/src/config.zig +++ b/src/config.zig @@ -47,6 +47,8 @@ pub const leader_path = paths: { .Callees = "lC", .Supertypes = "lt", .Subtypes = "lT", + .LookNext = "jn", + .LookPrev = "jp", .Del = "d", .DelAbove = null, .DelBelow = null, @@ -331,6 +333,8 @@ pub const command_line: []const Chord = &.{.{ .cp = ':' }}; pub const search: []const Chord = &.{.{ .cp = '/' }}; pub const search_next: []const Chord = &.{.{ .cp = 'n' }}; pub const search_prev: []const Chord = &.{.{ .cp = 'N' }}; +pub const search_selection: []const Chord = &.{.{ .cp = '*', .alt = true }}; +pub const search_selection_word: []const Chord = &.{.{ .cp = '*' }}; pub const pipe_selection: []const Chord = &.{.{ .cp = '|' }}; pub const pipe_selection_to: []const Chord = &.{.{ .cp = '|', .alt = true }}; pub const insert_output: []const Chord = &.{.{ .cp = '!' }}; diff --git a/src/look.zig b/src/look.zig index 6ba6a8d0..5795979f 100644 --- a/src/look.zig +++ b/src/look.zig @@ -542,7 +542,10 @@ pub fn submitSearch(p: *Pardes, id: usize) void { const pane = p.panes[id] orelse return; if (normal.selRegexArmed(pane)) |a| { // helix keeps the pattern in `/` - if (a.pat.len > 0) p.registers.put(p.gpa, '/', a.pat, 0, 1, true); + if (a.pat.len > 0) { + p.registers.put(p.gpa, '/', a.pat, 0, 1, true); + p.registers.last_search = '/'; + } return if (p.promptTarget(pane)) |t| normal.applySelRegex(p, pane, t, a.pat, a.mode); } const armed = pane.promptText() orelse return; @@ -556,7 +559,13 @@ pub fn submitSearch(p: *Pardes, id: usize) void { else .text; _ = runSearch(p, id, armed[slash + 1 ..], kind, .top, true) catch |err| return p.reportError(id, "search", err); - if (kind == .text) lookFirstHit(p, id); + if (kind == .text) { + var pattern: std.ArrayList(u8) = .empty; + normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch return; + p.registers.put(p.gpa, '/', pattern.items, 0, 1, true); + p.registers.last_search = '/'; + lookFirstHit(p, id); + } } fn lookFirstHit(p: *Pardes, id: usize) void { @@ -2752,7 +2761,6 @@ test "Look on a diff under each git prefix opens the repository's file, and a re } } - test "Look on a diff line is the look of the address it names, selected by hand: a cached patch, the checkout elsewhere" { if (!platform_has_fs) return; const io = std.testing.io; diff --git a/src/modal.zig b/src/modal.zig index 316a66fa..548524ae 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -157,6 +157,8 @@ pub const Normal = struct { search, search_next, search_prev, + search_selection, + search_selection_word, }; pub const Input = struct { @@ -355,7 +357,8 @@ pub const Normal = struct { command_line, pipe_selection: PipeBehavior, search, - search_step: Direction, + search_step: struct { direction: Direction, count: u32 }, + search_selection: bool, goto_word, macro_record, macro_replay: u32, @@ -373,6 +376,7 @@ pub const Normal = struct { .pipe_selection, .search, .search_step, + .search_selection, .macro_record, .macro_replay, .node, @@ -676,8 +680,10 @@ pub const Normal = struct { if (key.has(.macro_replay)) return resultAction(.{ .macro_replay = count }); if (key.has(.repeat_insert)) return resultAction(.{ .repeat_insert = count }); if (key.has(.search)) return resultAction(.search); - if (key.has(.search_next)) return resultAction(.{ .search_step = .forward }); - if (key.has(.search_prev)) return resultAction(.{ .search_step = .backward }); + if (key.has(.search_selection)) return resultAction(.{ .search_selection = false }); + if (key.has(.search_selection_word)) return resultAction(.{ .search_selection = true }); + if (key.has(.search_next)) return resultAction(.{ .search_step = .{ .direction = .forward, .count = count } }); + if (key.has(.search_prev)) return resultAction(.{ .search_step = .{ .direction = .backward, .count = count } }); return .unbound; } @@ -1420,6 +1426,17 @@ fn wordClassAt(text: []const u8, off: usize) WordClass { }; } +pub fn searchWordAt(text: []const u8, off: usize) bool { + return off < text.len and wordClassAt(text, off) == .word; +} + +pub fn searchWordBefore(text: []const u8, off: usize) bool { + if (off == 0) return false; + var previous = off - 1; + while (previous > 0 and text[previous] & 0xc0 == 0x80) previous -= 1; + return searchWordAt(text, previous); +} + fn isWordWhitespace(c: WordClass) bool { // Rust char::is_whitespace (includes line endings) return c == .ws or c == .eol; } diff --git a/src/normal.zig b/src/normal.zig index aec6b983..fad1836b 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -168,6 +168,168 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: m t.setRanges(text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO) } +/// Search only the primary range, as Helix does. Select mode adds a new +/// match and makes it primary; normal mode replaces only the primary. +fn searchStep(p: *Pardes, t: *Text, text: []const u8, direction: modal.Normal.Direction, count: u32) void { + const name = if (p.register != 0) p.register else p.registers.last_search; + const pat = p.registers.value(name, 0) orelse return; + var re = SearchRegex.compile(p.scratch.allocator(), pat) catch { + p.setMessage(p.active, "invalid search pattern"); + return; + }; + var hay = text; + if (for (pat) |c| { + if (std.ascii.isUpper(c)) break false; + } else true) { + const lower = p.scratch.allocator().dupe(u8, text) catch return; + for (lower) |*c| c.* = std.ascii.toLower(c.*); + hay = lower; + } + for (0..count) |_| { + var ranges: [Text.max_selections]modal.Selection = undefined; + const got = t.ranges(text, 0, &ranges); + const old = ranges[got.pri]; + const from = @min(old.anchor, old.head); + const to = @max(old.anchor, old.head); + var wrapped = false; + const found = (if (direction == .forward) blk: { + if (tryFind(&re, hay, to, hay.len)) |h| break :blk h; + wrapped = true; + break :blk tryFind(&re, hay, 0, hay.len); + } else blk: { + if (lastMatch(&re, hay, 0, from)) |h| break :blk h; + wrapped = true; + break :blk lastMatch(&re, hay, from, hay.len); + }) orelse { + p.setMessage(p.active, "no more matches"); + return; + }; + if (found.end == 0) return; + const next: modal.Selection = if (old.anchor > old.head) + .{ .anchor = found.end, .head = found.start } + else + .{ .anchor = found.start, .head = found.end }; + if (t.select and got.n < ranges.len) { + ranges[got.n] = next; + t.setRanges(text, ranges[0 .. got.n + 1], &.{}, got.n, true); + } else { + ranges[got.pri] = next; + t.setRanges(text, ranges[0..got.n], &.{}, got.pri, true); + } + if (wrapped) p.setMessage(p.active, "wrapped around document"); + } + t.show(); +} + +fn tryFind(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { + return re.find(hay, @min(from, hay.len), to); +} + +fn lastMatch(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { + var last: ?regexp.Regex.Match = null; + var at = from; + while (at <= to) { + const found = tryFind(re, hay, at, to) orelse break; + last = found; + at = if (found.end > found.start) found.end else modal.nextGrapheme(hay, found.end); + if (at <= found.start) break; + } + return last; +} + +pub fn searchSelection(p: *Pardes, t: *Text, text: []const u8, boundary: bool) void { + var ranges: [Text.max_selections]modal.Selection = undefined; + const got = t.ranges(text, 0, &ranges); + var pattern: std.ArrayList(u8) = .empty; + const arena = p.scratch.allocator(); + for (ranges[0..got.n], 0..) |r, i| { + const from = @min(r.anchor, r.head); + const to = @min(text.len, @max(r.anchor, r.head)); + if (i > 0) pattern.append(arena, '|') catch return; + if (boundary and modal.searchWordAt(text, from) and !modal.searchWordBefore(text, from)) pattern.appendSlice(arena, "\\b") catch return; + appendSearchLiteral(&pattern, arena, text[from..to]) catch return; + if (boundary and to < text.len and modal.searchWordBefore(text, to) and !modal.searchWordAt(text, to)) pattern.appendSlice(arena, "\\b") catch return; + } + const name = if (p.register != 0) p.register else '/'; + p.registers.put(p.gpa, name, pattern.items, 0, 1, true); + p.registers.last_search = name; +} + +// mvzr's word boundary is ASCII-only. Strip outer boundaries and check +// them against Unicode characters for search-selection patterns. +const SearchRegex = struct { + const Branch = struct { re: regexp.Regex, start_word: bool, end_word: bool }; + branches: []Branch, + + fn compile(arena: std.mem.Allocator, pattern: []const u8) !SearchRegex { + if (std.mem.indexOf(u8, pattern, "\\b") == null) { + const branches = try arena.alloc(Branch, 1); + branches[0] = try branch(pattern); + return .{ .branches = branches }; + } + var branches: std.ArrayList(Branch) = .empty; + var from: usize = 0; + var depth: usize = 0; + var escaped = false; + var in_class = false; + for (pattern, 0..) |c, i| { + if (escaped) { + escaped = false; + continue; + } + if (c == '\\') { + escaped = true; + continue; + } + if (c == '[') in_class = true else if (c == ']') in_class = false; + if (in_class) continue; + if (c == '(') depth += 1 else if (c == ')') depth -|= 1; + if (c == '|' and depth == 0) { + try branches.append(arena, try branch(pattern[from..i])); + from = i + 1; + } + } + try branches.append(arena, try branch(pattern[from..])); + for (branches.items) |*b| b.re.steps = regexp.Regex.budget / branches.items.len; + return .{ .branches = branches.items }; + } + + fn branch(pattern: []const u8) !Branch { + var pat = pattern; + const start = std.mem.startsWith(u8, pat, "\\b"); + if (start) pat = pat[2..]; + const end = std.mem.endsWith(u8, pat, "\\b") and !std.mem.endsWith(u8, pat, "\\\\b"); + if (end) pat = pat[0 .. pat.len - 2]; + return .{ .re = try regexp.Regex.compile(pat), .start_word = start, .end_word = end }; + } + + fn find(self: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { + var best: ?regexp.Regex.Match = null; + for (self.branches) |*b| { + var at = from; + while (at <= to) { + const found = (b.re.find(hay, at, to, to) catch break) orelse break; + if ((!b.start_word or modal.searchWordBefore(hay, found.start) != modal.searchWordAt(hay, found.start)) and + (!b.end_word or modal.searchWordBefore(hay, found.end) != modal.searchWordAt(hay, found.end))) + { + if (best == null or found.start < best.?.start) best = found; + break; + } + at = modal.nextGrapheme(hay, found.start); + if (at <= found.start) break; + } + } + return best; + } +}; + +pub fn appendSearchLiteral(out: *std.ArrayList(u8), arena: std.mem.Allocator, text: []const u8) !void { + for (text) |c| { + if (std.mem.indexOfScalar(u8, "\\^$.[]()|*+?{}", c) != null) try out.append(arena, '\\'); + if (c == '\n') try out.appendSlice(arena, "\\n") else try out.append(arena, c); + } +} + /// The file's parse, made on the first key that walks it after an edit and /// kept until the next: never made again for a key that changed nothing. pub fn fileTree(p: *Pardes, f: *panes.File.State) ?*anyopaque { @@ -766,10 +928,8 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void }, .pipe_selection => |how| return p.startPrompt(pane, t, .{ .pipe = how }), .search => return p.startPrompt(pane, &pane.body, .{ .search = config.search_marker }), - .search_step => |direction| return look.lookWalk( - p, - if (direction == .forward) @as(i32, 1) else -1, - ), + .search_step => |step| return searchStep(p, t, text, step.direction, step.count), + .search_selection => |boundary| return searchSelection(p, t, text, boundary), .node => |walk| return nodeSelect(p, pane, t, walk), .goto_word => return startJump(p, pane, t), .object_jump => |jump| return objectJump(p, pane, t, text, range, jump.object, jump.direction == .forward, jump.count), diff --git a/src/pdf_view.zig b/src/pdf_view.zig index d5769ad3..567117bb 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -1843,7 +1843,7 @@ pub fn applyNormal( .leader => result.host = .leader, .command_line => result.host = .command_line, .search => result.host = .search, - .search_step => |direction| result.host = if (direction == .forward) + .search_step => |step| result.host = if (step.direction == .forward) .search_forward else .search_backward, diff --git a/src/tutor.txt b/src/tutor.txt index 7492b058..8f5cf241 100644 --- a/src/tutor.txt +++ b/src/tutor.txt @@ -97,7 +97,7 @@ 1. `Look` :20 here: the cursor goes to line 20 of this pane. 2. `Look` :/UNSAVED/ to go to the next match of UNSAVED. 3. Press /, type keys, press Enter: a +Search lists the lines with - keys and the cursor goes to the first. n and N step through. + keys and the cursor goes to the first. n and N select search matches. -> Guide: Look @@ -256,7 +256,8 @@ typed | filter every selection through the shell / case-insensitive SUBSTRING search, one hit a line; the regex lives on s and S - n / N the next/previous text `Look` would open, as above + n / N next/previous search match (Helix); v adds matches + SPC j n/p `LookNext`/`LookPrev`: select locations; Enter opens Ctrl-c comment or uncomment the lines VIEWPORT @@ -341,7 +342,7 @@ typed SPC is the leader (SPC ? is `Help`) vs HELIX selection is LINE-first (x), v for characters; / is a - substring search; n/N walk what `Look` would open. + substring search; n/N repeat it in the current text. vs VIM no verb+noun: the motion already selected, so wd is what dw was; Esc goes back a pane; bare G does nothing. vs BOTH a terminal is just a pane, and the session can outlive diff --git a/test/hxcases/cases.jsonl b/test/hxcases/cases.jsonl index f36afe11..b7fdc4c9 100644 --- a/test/hxcases/cases.jsonl +++ b/test/hxcases/cases.jsonl @@ -592,3 +592,67 @@ {"name": "comment-then-insert", "pane": "file", "text": "alpha\n", "keys": "<C-c>iz<esc>"} {"name": "comment-after-sel-regex", "pane": "file", "text": "alpha\nbeta\ngamma\n", "keys": "%sa<ret><C-c>"} {"name": "comment-after-split-regex", "pane": "file", "text": "a,b\nc,d\n", "keys": "%S,<ret><C-c>"} +{"name": "search-repeat-next", "pane": "file", "text": "one one one\n", "keys": "w*n"} +{"name": "search-repeat-next-tty", "pane": "tty", "text": "one one one\n", "keys": "w*n"} +{"name": "search-repeat-prev", "pane": "file", "text": "one one one\n", "keys": "w*N"} +{"name": "search-repeat-prev-tty", "pane": "tty", "text": "one one one\n", "keys": "w*N"} +{"name": "search-repeat-wrap", "pane": "file", "text": "one one one\n", "keys": "w*3n"} +{"name": "search-repeat-wrap-tty", "pane": "tty", "text": "one one one\n", "keys": "w*3n"} +{"name": "search-repeat-count", "pane": "file", "text": "one one one\n", "keys": "w*2n"} +{"name": "search-repeat-count-tty", "pane": "tty", "text": "one one one\n", "keys": "w*2n"} +{"name": "search-repeat-reverse-count", "pane": "file", "text": "one one one\n", "keys": "w*2N"} +{"name": "search-repeat-reverse-count-tty", "pane": "tty", "text": "one one one\n", "keys": "w*2N"} +{"name": "search-repeat-select", "pane": "file", "text": "one one one\n", "keys": "w*vn"} +{"name": "search-repeat-select-tty", "pane": "tty", "text": "one one one\n", "keys": "w*vn"} +{"name": "search-repeat-select-count", "pane": "file", "text": "one one one\n", "keys": "w*v2n"} +{"name": "search-repeat-select-count-tty", "pane": "tty", "text": "one one one\n", "keys": "w*v2n"} +{"name": "search-repeat-select-back", "pane": "file", "text": "one one one\n", "keys": "w*vN"} +{"name": "search-repeat-select-back-tty", "pane": "tty", "text": "one one one\n", "keys": "w*vN"} +{"name": "search-repeat-keep-secondary", "pane": "file", "text": "one one one\n", "keys": "%sone<ret>n"} +{"name": "search-repeat-keep-secondary-tty", "pane": "tty", "text": "one one one\n", "keys": "%sone<ret>n"} +{"name": "search-repeat-reverse-selection", "pane": "file", "text": "one one one\n", "keys": "w*<A-;>n"} +{"name": "search-repeat-reverse-selection-tty", "pane": "tty", "text": "one one one\n", "keys": "w*<A-;>n"} +{"name": "search-repeat-smart-case", "pane": "file", "text": "one ONE one\n", "keys": "%sone<ret>,n"} +{"name": "search-repeat-smart-case-tty", "pane": "tty", "text": "one ONE one\n", "keys": "%sone<ret>,n"} +{"name": "search-repeat-upper-case", "pane": "file", "text": "one ONE ONE\n", "keys": "%sONE<ret>,n"} +{"name": "search-repeat-upper-case-tty", "pane": "tty", "text": "one ONE ONE\n", "keys": "%sONE<ret>,n"} +{"name": "search-repeat-named", "pane": "file", "text": "one one one\n", "keys": "w\"a*\"an"} +{"name": "search-repeat-named-tty", "pane": "tty", "text": "one one one\n", "keys": "w\"a*\"an"} +{"name": "search-repeat-remember-named", "pane": "file", "text": "one one one\n", "keys": "w\"a*n"} +{"name": "search-repeat-remember-named-tty", "pane": "tty", "text": "one one one\n", "keys": "w\"a*n"} +{"name": "search-repeat-literal", "pane": "file", "text": "a.b a.b axb\n", "keys": "3l<A-*>n"} +{"name": "search-repeat-literal-tty", "pane": "tty", "text": "a.b a.b axb\n", "keys": "3l<A-*>n"} +{"name": "search-repeat-newline", "pane": "file", "text": "alpha\nbeta\nalpha\nbeta\n", "keys": "%salpha<ret>,n"} +{"name": "search-repeat-newline-tty", "pane": "tty", "text": "alpha\nbeta\nalpha\nbeta\n", "keys": "%salpha<ret>,n"} +{"name": "search-repeat-no-reg", "pane": "file", "text": "one one one\n", "keys": "n"} +{"name": "search-repeat-no-reg-tty", "pane": "tty", "text": "one one one\n", "keys": "n"} +{"name": "search-repeat-missing", "pane": "file", "text": "one one one\n", "keys": "\"an"} +{"name": "search-repeat-missing-tty", "pane": "tty", "text": "one one one\n", "keys": "\"an"} +{"name": "search-repeat-regexp", "pane": "file", "text": "a1 a2 a3\n", "keys": "%sa[0-9]<ret>,n"} +{"name": "search-repeat-regexp-tty", "pane": "tty", "text": "a1 a2 a3\n", "keys": "%sa[0-9]<ret>,n"} +{"name": "search-repeat-zero", "pane": "file", "text": "abc abc\n", "keys": "%s$<ret>,n"} +{"name": "search-repeat-zero-tty", "pane": "tty", "text": "abc abc\n", "keys": "%s$<ret>,n"} +{"name": "search-repeat-unicode", "pane": "file", "text": "界 界 界\n", "keys": "w*n"} +{"name": "search-repeat-unicode-tty", "pane": "tty", "text": "界 界 界\n", "keys": "w*n"} +{"name": "search-repeat-combining", "pane": "file", "text": "á á á\n", "keys": "w*n"} +{"name": "search-repeat-combining-tty", "pane": "tty", "text": "á á á\n", "keys": "w*n"} +{"name": "search-repeat-word-boundary", "pane": "file", "text": "one oneself one\n", "keys": "e<A-*>n"} +{"name": "search-repeat-word-boundary-tty", "pane": "tty", "text": "one oneself one\n", "keys": "e<A-*>n"} +{"name": "search-repeat-word-normal", "pane": "file", "text": "one oneself one\n", "keys": "e*n"} +{"name": "search-repeat-word-normal-tty", "pane": "tty", "text": "one oneself one\n", "keys": "e*n"} +{"name": "search-repeat-word-extend-wrap", "pane": "file", "text": "one one one\n", "keys": "e*v4n"} +{"name": "search-repeat-word-extend-wrap-tty", "pane": "tty", "text": "one one one\n", "keys": "e*v4n"} +{"name": "search-repeat-word-reverse-wrap", "pane": "file", "text": "one one one\n", "keys": "e*4N"} +{"name": "search-repeat-word-reverse-wrap-tty", "pane": "tty", "text": "one one one\n", "keys": "e*4N"} +{"name": "search-repeat-unicode-boundary", "pane": "file", "text": "界 界界 界\n", "keys": "e*n"} +{"name": "search-repeat-unicode-boundary-tty", "pane": "tty", "text": "界 界界 界\n", "keys": "e*n"} +{"name": "search-repeat-unicode-alternatives", "pane": "file", "text": "界 語 界 語\n", "keys": "%s[界語]<ret>*n"} +{"name": "search-repeat-unicode-alternatives-tty", "pane": "tty", "text": "界 語 界 語\n", "keys": "%s[界語]<ret>*n"} +{"name": "search-repeat-multisel-extend", "pane": "file", "text": "one two one two\n", "keys": "%sone|two<ret>*vn"} +{"name": "search-repeat-multisel-extend-tty", "pane": "tty", "text": "one two one two\n", "keys": "%sone|two<ret>*vn"} +{"name": "search-repeat-backward-zero", "pane": "file", "text": "abc abc\n", "keys": "%s$<ret>,2N"} +{"name": "search-repeat-backward-zero-tty", "pane": "tty", "text": "abc abc\n", "keys": "%s$<ret>,2N"} +{"name": "search-repeat-adjacent", "pane": "file", "text": "aaa\n", "keys": "*2n"} +{"name": "search-repeat-adjacent-tty", "pane": "tty", "text": "aaa\n", "keys": "*2n"} +{"name": "search-repeat-direction-extend", "pane": "file", "text": "one one one\n", "keys": "e*<A-;>vn"} +{"name": "search-repeat-direction-extend-tty", "pane": "tty", "text": "one one one\n", "keys": "e*<A-;>vn"} diff --git a/test/hxcases/goldens.jsonl b/test/hxcases/goldens.jsonl index 2dab15c0..bfa479be 100644 --- a/test/hxcases/goldens.jsonl +++ b/test/hxcases/goldens.jsonl @@ -592,3 +592,67 @@ {"name":"comment-then-insert","text":"# zalpha\n","mode":"normal","cursor":{"row":0,"col":3},"anchor":{"row":0,"col":3}} {"name":"comment-after-sel-regex","text":"# alpha\n# beta\n# gamma\n","mode":"normal","cursor":{"row":0,"col":2},"anchor":{"row":0,"col":2},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":2}},{"cursor":{"row":0,"col":6},"anchor":{"row":0,"col":6}},{"cursor":{"row":1,"col":5},"anchor":{"row":1,"col":5}},{"cursor":{"row":2,"col":3},"anchor":{"row":2,"col":3}},{"cursor":{"row":2,"col":6},"anchor":{"row":2,"col":6}}],"primary":0} {"name":"comment-after-split-regex","text":"# a,b\n# c,d\n","mode":"normal","cursor":{"row":0,"col":2},"anchor":{"row":0,"col":2},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":2}},{"cursor":{"row":1,"col":2},"anchor":{"row":0,"col":4}},{"cursor":{"row":1,"col":5},"anchor":{"row":1,"col":4}}],"primary":0} +{"name":"search-repeat-next","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-next-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-prev","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-prev-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-wrap","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-wrap-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-count","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-count-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-reverse-count","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-reverse-count-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-select","text":"one one one\n","mode":"select","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}}],"primary":1} +{"name":"search-repeat-select-tty","text":"one one one\n","mode":"select","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}}],"primary":1} +{"name":"search-repeat-select-count","text":"one one one\n","mode":"select","cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0},"sels":[{"cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}}],"primary":0} +{"name":"search-repeat-select-count-tty","text":"one one one\n","mode":"select","cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0},"sels":[{"cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}}],"primary":0} +{"name":"search-repeat-select-back","text":"one one one\n","mode":"select","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}}],"primary":1} +{"name":"search-repeat-select-back-tty","text":"one one one\n","mode":"select","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":3},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}}],"primary":1} +{"name":"search-repeat-keep-secondary","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}},{"cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}}],"primary":0} +{"name":"search-repeat-keep-secondary-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}},{"cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}}],"primary":0} +{"name":"search-repeat-reverse-selection","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":4},"anchor":{"row":0,"col":7}} +{"name":"search-repeat-reverse-selection-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":4},"anchor":{"row":0,"col":7}} +{"name":"search-repeat-smart-case","text":"one ONE one\n","mode":"normal","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-smart-case-tty","text":"one ONE one\n","mode":"normal","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-upper-case","text":"one ONE ONE\n","mode":"normal","cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}} +{"name":"search-repeat-upper-case-tty","text":"one ONE ONE\n","mode":"normal","cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}} +{"name":"search-repeat-named","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-named-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-remember-named","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-remember-named-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-literal","text":"a.b a.b axb\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":7}} +{"name":"search-repeat-literal-tty","text":"a.b a.b axb\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":7}} +{"name":"search-repeat-newline","text":"alpha\nbeta\nalpha\nbeta\n","mode":"normal","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":0}} +{"name":"search-repeat-newline-tty","text":"alpha\nbeta\nalpha\nbeta\n","mode":"normal","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":0}} +{"name":"search-repeat-no-reg","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-no-reg-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-missing","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-missing-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-regexp","text":"a1 a2 a3\n","mode":"normal","cursor":{"row":0,"col":4},"anchor":{"row":0,"col":3}} +{"name":"search-repeat-regexp-tty","text":"a1 a2 a3\n","mode":"normal","cursor":{"row":0,"col":4},"anchor":{"row":0,"col":3}} +{"name":"search-repeat-zero","text":"abc abc\n","mode":"normal","cursor":{"row":1,"col":0},"anchor":{"row":1,"col":0}} +{"name":"search-repeat-zero-tty","text":"abc abc\n","mode":"normal","cursor":{"row":1,"col":0},"anchor":{"row":1,"col":0}} +{"name":"search-repeat-unicode","text":"界 界 界\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-unicode-tty","text":"界 界 界\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-combining","text":"á á á\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-combining-tty","text":"á á á\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-word-boundary","text":"one oneself one\n","mode":"normal","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-word-boundary-tty","text":"one oneself one\n","mode":"normal","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}} +{"name":"search-repeat-word-normal","text":"one oneself one\n","mode":"normal","cursor":{"row":0,"col":14},"anchor":{"row":0,"col":12}} +{"name":"search-repeat-word-normal-tty","text":"one oneself one\n","mode":"normal","cursor":{"row":0,"col":14},"anchor":{"row":0,"col":12}} +{"name":"search-repeat-word-extend-wrap","text":"one one one\n","mode":"select","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}},{"cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}}],"primary":1} +{"name":"search-repeat-word-extend-wrap-tty","text":"one one one\n","mode":"select","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}},{"cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}}],"primary":1} +{"name":"search-repeat-word-reverse-wrap","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}} +{"name":"search-repeat-word-reverse-wrap-tty","text":"one one one\n","mode":"normal","cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}} +{"name":"search-repeat-unicode-boundary","text":"界 界界 界\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":3}} +{"name":"search-repeat-unicode-boundary-tty","text":"界 界界 界\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":3}} +{"name":"search-repeat-unicode-alternatives","text":"界 語 界 語\n","mode":"normal","cursor":{"row":0,"col":4},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":4},"anchor":{"row":0,"col":4}},{"cursor":{"row":0,"col":8},"anchor":{"row":0,"col":8}},{"cursor":{"row":0,"col":12},"anchor":{"row":0,"col":12}}],"primary":0} +{"name":"search-repeat-unicode-alternatives-tty","text":"界 語 界 語\n","mode":"normal","cursor":{"row":0,"col":4},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":4},"anchor":{"row":0,"col":4}},{"cursor":{"row":0,"col":8},"anchor":{"row":0,"col":8}},{"cursor":{"row":0,"col":12},"anchor":{"row":0,"col":12}}],"primary":0} +{"name":"search-repeat-multisel-extend","text":"one two one two\n","mode":"select","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}},{"cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}},{"cursor":{"row":0,"col":14},"anchor":{"row":0,"col":12}}],"primary":1} +{"name":"search-repeat-multisel-extend-tty","text":"one two one two\n","mode":"select","cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":0}},{"cursor":{"row":0,"col":6},"anchor":{"row":0,"col":4}},{"cursor":{"row":0,"col":10},"anchor":{"row":0,"col":8}},{"cursor":{"row":0,"col":14},"anchor":{"row":0,"col":12}}],"primary":1} +{"name":"search-repeat-backward-zero","text":"abc abc\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":7}} +{"name":"search-repeat-backward-zero-tty","text":"abc abc\n","mode":"normal","cursor":{"row":0,"col":7},"anchor":{"row":0,"col":7}} +{"name":"search-repeat-adjacent","text":"aaa\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-adjacent-tty","text":"aaa\n","mode":"normal","cursor":{"row":0,"col":0},"anchor":{"row":0,"col":0}} +{"name":"search-repeat-direction-extend","text":"one one one\n","mode":"select","cursor":{"row":0,"col":4},"anchor":{"row":0,"col":6},"sels":[{"cursor":{"row":0,"col":0},"anchor":{"row":0,"col":2}},{"cursor":{"row":0,"col":4},"anchor":{"row":0,"col":6}}],"primary":1} +{"name":"search-repeat-direction-extend-tty","text":"one one one\n","mode":"select","cursor":{"row":0,"col":4},"anchor":{"row":0,"col":6},"sels":[{"cursor":{"row":0,"col":0},"anchor":{"row":0,"col":2}},{"cursor":{"row":0,"col":4},"anchor":{"row":0,"col":6}}],"primary":1} diff --git a/test/hxcases/golf-waivers.jsonl b/test/hxcases/golf-waivers.jsonl index eb1f824b..e69de29b 100644 --- a/test/hxcases/golf-waivers.jsonl +++ b/test/hxcases/golf-waivers.jsonl @@ -1,7 +0,0 @@ -{"name":"golf-reverse-golf-example-07","reason":"pardes n/N/* are the acme look ring, by decision: \"\"N, n and * do not walk the search register","reference":{"name":"golf-reverse-golf-example-07","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":0,"col":2},"anchor":{"row":0,"col":11},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":11}},{"cursor":{"row":0,"col":16},"anchor":{"row":0,"col":25}}],"primary":0},"expected":{"name":"golf-reverse-golf-example-07","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":0,"col":16},"anchor":{"row":0,"col":25}}} -{"name":"golf-reverse-golf-example-08","reason":"pardes n/N/* are the acme look ring, by decision: \"\"N, n and * do not walk the search register","reference":{"name":"golf-reverse-golf-example-08","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":2,"col":24},"anchor":{"row":2,"col":32},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":11}},{"cursor":{"row":0,"col":16},"anchor":{"row":0,"col":25}},{"cursor":{"row":2,"col":24},"anchor":{"row":2,"col":32}}],"primary":2},"expected":{"name":"golf-reverse-golf-example-08","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":0,"col":16},"anchor":{"row":0,"col":25}}} -{"name":"golf-reverse-golf-example-09","reason":"pardes n/N/* are the acme look ring, by decision: \"\"N, n and * do not walk the search register","reference":{"name":"golf-reverse-golf-example-09","text":"# camelCase to snake_case\n\nRename all fields to be snake_case.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":0,"col":2},"anchor":{"row":0,"col":10},"sels":[{"cursor":{"row":0,"col":2},"anchor":{"row":0,"col":10}},{"cursor":{"row":0,"col":15},"anchor":{"row":0,"col":24}},{"cursor":{"row":2,"col":24},"anchor":{"row":2,"col":33}}],"primary":0},"expected":{"name":"golf-reverse-golf-example-09","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":0,"col":16},"anchor":{"row":0,"col":25}}} -{"name":"golf-reverse-golf-example-10","reason":"pardes n/N/* are the acme look ring, by decision: \"\"N, n and * do not walk the search register","reference":{"name":"golf-reverse-golf-example-10","text":"# camelCase to snake_case\n\nRename all fields to be snake_case.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":14,"col":3},"anchor":{"row":0,"col":0}},"expected":{"name":"golf-reverse-golf-example-10","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":14,"col":3},"anchor":{"row":0,"col":0}}} -{"name":"golf-reverse-golf-example-11","reason":"pardes n/N/* are the acme look ring, by decision: \"\"N, n and * do not walk the search register","reference":{"name":"golf-reverse-golf-example-11","text":"# camelCase to snake_case\n\nRename all fields to be snake_case.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":6,"col":3},"anchor":{"row":6,"col":0},"sels":[{"cursor":{"row":6,"col":3},"anchor":{"row":6,"col":0}},{"cursor":{"row":12,"col":3},"anchor":{"row":12,"col":0}}],"primary":0},"expected":{"name":"golf-reverse-golf-example-11","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":6,"col":3},"anchor":{"row":6,"col":0},"sels":[{"cursor":{"row":6,"col":3},"anchor":{"row":6,"col":0}},{"cursor":{"row":12,"col":3},"anchor":{"row":12,"col":0}}],"primary":0}} -{"name":"golf-reverse-golf-example-12","reason":"pardes n/N/* are the acme look ring, by decision: \"\"N, n and * do not walk the search register","reference":{"name":"golf-reverse-golf-example-12","text":"# camelCase to snake_case\n\nRename all fields to be snake_case.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":7,"col":41},"anchor":{"row":6,"col":0},"sels":[{"cursor":{"row":7,"col":41},"anchor":{"row":6,"col":0}},{"cursor":{"row":13,"col":39},"anchor":{"row":12,"col":0}}],"primary":0},"expected":{"name":"golf-reverse-golf-example-12","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n\n## After\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n","mode":"select","cursor":{"row":7,"col":41},"anchor":{"row":6,"col":0},"sels":[{"cursor":{"row":7,"col":41},"anchor":{"row":6,"col":0}},{"cursor":{"row":13,"col":39},"anchor":{"row":12,"col":0}}],"primary":0}} -{"name":"golf-reverse-golf-example","reason":"pardes n/N/* are the acme look ring, by decision: \"\"N, n and * do not walk the search register","reference":{"name":"golf-reverse-golf-example","text":"# camelCase to snake_case\n\nRename all fields to be snake_case.\n\n## Before\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n\n## After\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n","mode":"select","cursor":{"row":13,"col":41},"anchor":{"row":12,"col":0},"sels":[{"cursor":{"row":7,"col":39},"anchor":{"row":6,"col":0}},{"cursor":{"row":13,"col":41},"anchor":{"row":12,"col":0}}],"primary":1},"expected":{"name":"golf-reverse-golf-example","text":"# snake_case to snake_case\n\nRename all fields to be camelCase.\n\n## Before\n\n```js\nconst userProfile = {firstName: \"John\"};\n```\n\n## After\n\n```js\nconst user_profile = {first_name: \"John\"};\n```\n","mode":"select","cursor":{"row":13,"col":41},"anchor":{"row":12,"col":0},"sels":[{"cursor":{"row":7,"col":39},"anchor":{"row":6,"col":0}},{"cursor":{"row":13,"col":41},"anchor":{"row":12,"col":0}}],"primary":1}} diff --git a/test/output.zig b/test/output.zig index 51d620c0..6ea6f6fa 100644 --- a/test/output.zig +++ b/test/output.zig @@ -219,11 +219,11 @@ test "reference Look selects the next sorted row from the captured request and k try std.testing.expectEqual(results.serial, p.look_walk_owner.?); try std.testing.expectEqual(@as(i32, 3), results.look_at.?.row); const available = p.freeSlot(); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(rid, p.active); try std.testing.expectEqual(@as(i32, 4), results.body.cur_row); try std.testing.expectEqual(available, p.freeSlot()); - p.update(.{ .key = .{ .cp = 'N' } }); + lookKey(p, 'N'); try std.testing.expectEqual(@as(i32, 3), results.body.cur_row); p.active = 0; @@ -791,7 +791,7 @@ fn selectedOutputText(pane: *const pardes.Pane) ?[]const u8 { return line[lo..@min(line.len, hi + 1)]; } -test "n/N in ordinary text skips comment slashes and retains real paths" { +test "LookNext/LookPrev in ordinary text skips comment slashes and retains real paths" { if (platform == .web) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); defer p.deinit(); @@ -808,7 +808,7 @@ test "n/N in ordinary text skips comment slashes and retains real paths" { .{ .key = 'N', .row = 4, .text = "/tmp" }, .{ .key = 'N', .row = 3, .text = "/" }, }) |step| { - p.update(.{ .key = .{ .cp = step.key } }); + lookKey(p, step.key); try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqual(step.row, pane.body.cur_row); try std.testing.expectEqualStrings(step.text, selectedOutputText(pane) orelse ""); @@ -816,7 +816,7 @@ test "n/N in ordinary text skips comment slashes and retains real paths" { } } -test "n/N skips formatted context and selects comment match locations" { +test "LookNext/LookPrev skips formatted context and selects comment match locations" { if (!pardes.syntax.enabled) return error.SkipZigTest; for ([_]panes.Output.Origin{ .search, .{ .query = .references } }) |origin| { for ([_]bool{ false, true }) |tslocations| { @@ -860,7 +860,7 @@ test "n/N skips formatted context and selects comment match locations" { .{ .key = 'N', .match = 1 }, .{ .key = 'N', .match = 0 }, }) |step| { - p.update(.{ .key = .{ .cp = step.key } }); + lookKey(p, step.key); try std.testing.expectEqual(id, p.active); const row = matches[step.match]; try std.testing.expectEqual(@as(i32, @intCast(row)), result.body.cur_row); @@ -876,9 +876,9 @@ test "n/N skips formatted context and selects comment match locations" { // The dot came back on the match it was on (the first), so the // walk goes on from there. try std.testing.expectEqual(@as(i32, @intCast(matches[0])), restored_result.body.cur_row); - restored.update(.{ .key = .{ .cp = 'n' } }); + lookKey(restored, 'n'); try std.testing.expectEqual(@as(i32, @intCast(matches[1])), restored_result.body.cur_row); - restored.update(.{ .key = .{ .cp = 'N' } }); + lookKey(restored, 'N'); try std.testing.expectEqual(@as(i32, @intCast(matches[0])), restored_result.body.cur_row); const restored_file = &restored_result.file.?; const last = modal.lineSlice(restored_file.content, matches[0]); @@ -887,7 +887,7 @@ test "n/N skips formatted context and selects comment match locations" { } } -test "n/N selects one output location per row and opens nothing" { +test "LookNext/LookPrev selects one output location per row and opens nothing" { if (platform == .web) return; var cwd_buf: [4096]u8 = undefined; var path_buf: [4096]u8 = undefined; @@ -900,20 +900,20 @@ test "n/N selects one output location per row and opens nothing" { const results = p.panes[rid].?; const panes_before = p.freeSlot(); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(rid, p.active); try std.testing.expectEqual(panes_before, p.freeSlot()); try std.testing.expect(results.body.vsel.active and results.body.vsel.explicit); try std.testing.expectEqualStrings("build.zig:1:1", selectedOutputText(results) orelse ""); try std.testing.expectEqual(panes.Output.Grain.line, panes.Output.grain(results.file.?.output)); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(@as(i32, 1), results.body.cur_row); try std.testing.expectEqualStrings("mise.toml", selectedOutputText(results) orelse ""); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(@as(i32, 3), results.body.cur_row); // row 2 is not look-able try std.testing.expectEqualStrings("uucode_config.zig:7:1", selectedOutputText(results) orelse ""); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(@as(i32, 0), results.body.cur_row); // ring seam p.update(.{ .key = .{ .cp = Key.enter } }); @@ -922,7 +922,7 @@ test "n/N selects one output location per row and opens nothing" { try std.testing.expectEqual(panes.Output.Grain.word, panes.Output.grain(p.panes[p.active].?.file.?.output)); } -test "n/N resumes the result output whose Look moved focus away" { +test "LookNext/LookPrev resumes the result output whose Look moved focus away" { if (platform == .web) return; var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); @@ -945,10 +945,10 @@ test "n/N resumes the result output whose Look moved focus away" { try std.testing.expect(results.look_at != null); try std.testing.expectEqual(results.serial, p.look_walk_owner orelse return error.MissingLookOwner); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(rid, p.active); try std.testing.expectEqual(first + 1, results.body.cur_row); - p.update(.{ .key = .{ .cp = 'N' } }); + lookKey(p, 'N'); try std.testing.expectEqual(first, results.body.cur_row); // A later no-match answer has no position to resume and therefore cannot @@ -965,7 +965,7 @@ test "n/N resumes the result output whose Look moved focus away" { null, ); try std.testing.expectEqual(owner, p.look_walk_owner.?); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(rid, p.active); try std.testing.expectEqual(first + 1, results.body.cur_row); @@ -981,7 +981,7 @@ test "n/N resumes the result output whose Look moved focus away" { try std.testing.expect(p.paneBySerial(owner) == null); } -test "N exactly reverses n across output panes and the ring seam" { +test "LookPrev exactly reverses LookNext across output panes and the ring seam" { if (platform == .web) return; var cwd_buf: [4096]u8 = undefined; var path_buf: [4096]u8 = undefined; @@ -1002,17 +1002,17 @@ test "N exactly reverses n across output panes and the ring seam" { return .{ .pane = pp.active, .row = pane.body.cur_row, .col = pane.body.cur_col }; } }.at; - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); const base = here(p); var trail: [12]Mark = undefined; for (&trail) |*mark| { - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); mark.* = here(p); } var i = trail.len; while (i > 0) { i -= 1; - p.update(.{ .key = .{ .cp = 'N' } }); + lookKey(p, 'N'); const want = if (i == 0) base else trail[i - 1]; try std.testing.expectEqual(want, here(p)); } @@ -1068,20 +1068,20 @@ test "Themes lists the ring in sections and skips headings in both directions" { // Opening an imported theme's selector must still begin with the natives. // Walk across the section break without selecting or executing a heading. for (pardes.themes[0 .. brk + 1]) |theme| { - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(tid, p.active); const selected = selectedOutputText(list) orelse return error.MissingThemeSection; try std.testing.expectEqualStrings(theme.name, selected["Theme ".len..]); try std.testing.expectEqual(original_theme, p.settings.theme); } - p.update(.{ .key = .{ .cp = 'N' } }); + lookKey(p, 'N'); const previous = selectedOutputText(list) orelse return error.MissingThemeSection; try std.testing.expectEqualStrings(pardes.themes[brk - 1].name, previous["Theme ".len..]); p.update(.{ .key = .{ .cp = Key.tab } }); try std.testing.expectEqual(brk - 1, p.settings.theme); } -test "n/N selects command outputs by whole row" { +test "LookNext/LookPrev selects command outputs by whole row" { if (platform == .web) return; var cwd_buf: [4096]u8 = undefined; var path_buf: [4096]u8 = undefined; @@ -1094,18 +1094,18 @@ test "n/N selects command outputs by whole row" { const tid = p.panes[p.active].?.search_pane orelse return error.MissingThemeList; const themes = p.panes[tid].?; try std.testing.expect(panes.Output.fileTraits(themes.file.?.output).commands); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); const row0 = std.mem.trimEnd(u8, modal.lineSlice(themes.file.?.content, 1), " \t\r"); try std.testing.expectEqualStrings(row0, selectedOutputText(themes) orelse ""); const theme_before = p.settings.theme; - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); p.update(.{ .key = .{ .cp = Key.tab } }); try std.testing.expect(p.settings.theme != theme_before); try std.testing.expect(p.executeBuiltinLine(0, "Look build.zig")); p.update(.tick); try std.testing.expect(p.active != 0); - p.update(.{ .key = .{ .cp = 'n' } }); + lookKey(p, 'n'); try std.testing.expectEqual(@as(usize, 0), p.active); } @@ -1661,7 +1661,7 @@ test "stacked search and LSP results retain source tint navigation and dump owne pane.body.mode = .normal; pardes.look.armLookWalk(p, id); for ([_]struct { key: u21, match: usize }{ .{ .key = 'n', .match = 0 }, .{ .key = 'n', .match = 1 }, .{ .key = 'N', .match = 0 } }) |step| { - p.update(.{ .key = .{ .cp = step.key } }); + lookKey(p, step.key); try std.testing.expectEqual(@as(i32, @intCast(matches[step.match])), pane.body.cur_row); const row = file.location_rows[matches[step.match]]; const line = modal.lineSlice(file.content, matches[step.match]); @@ -1686,9 +1686,9 @@ test "stacked search and LSP results retain source tint navigation and dump owne // The dot came back on the match it was on; the walk goes on // from it both ways, N wrapping to the last as it does live. try std.testing.expectEqual(@as(i32, @intCast(matches[0])), restored.panes[id].?.body.cur_row); - restored.update(.{ .key = .{ .cp = 'N' } }); + lookKey(restored, 'N'); try std.testing.expectEqual(@as(i32, @intCast(matches[1])), restored.panes[id].?.body.cur_row); - restored.update(.{ .key = .{ .cp = 'n' } }); + lookKey(restored, 'n'); try std.testing.expectEqual(@as(i32, @intCast(matches[0])), restored.panes[id].?.body.cur_row); try std.testing.expectEqualStrings(source_text, source.file.?.content); } @@ -1833,3 +1833,8 @@ test "location cache eviction retains early colors and honors disk and unsaved r try std.testing.expectEqual(@intFromEnum(pardes.syntax.Syn.comment), try Color.valueColor(file)); try std.testing.expectEqualStrings(comment, source.file.?.content); } + +fn lookKey(p: *Pardes, key: u21) void { + for ([_]u21{ ' ', 'j', if (key == 'N') 'p' else 'n' }) |cp| + p.update(.{ .key = .{ .cp = cp } }); +} diff --git a/test/snapshots/builtins.snap b/test/snapshots/builtins.snap index 849c83d3..8ae22a62 100644 --- a/test/snapshots/builtins.snap +++ b/test/snapshots/builtins.snap @@ -37,7 +37,7 @@ wait 10000 Theme stable 700 15000 # n moves through look-able text; it must not execute command names. -key n n n +key space j n space j n space j n wait 10000 Look enter, right-click wait 10000 Exec tab, middle-click key space w ? diff --git a/test/snapshots/find.snap b/test/snapshots/find.snap index 20a5e36f..b2e36973 100644 --- a/test/snapshots/find.snap +++ b/test/snapshots/find.snap @@ -41,25 +41,25 @@ stable 700 15000 snap results # n SELECTS row 1 and Enter looks it — a path, so the file OPENS, under the # list's text, and each file after it under the one before. -key n +key space j n key enter wait 10000 beta body stable 700 15000 snap first snapstyle first -key n +key space j n key enter wait 10000 gamma body stable 700 15000 snap second -key n +key space j n key enter wait 10000 alpha body stable 700 15000 snap third # N walks back up one row; Enter looks it, and the file is already open, so # the look just focuses it -key N +key space j p key enter stable 700 15000 snap back @@ -92,7 +92,7 @@ stable 700 10000 # rather than one buffer's rows: with nothing look-able here it carries on # into the list that DOES have some — the zqm one — and resumes it one row # past where the N above left it. Nothing opens; only the selection moved. -key n +key space j n stable 400 5000 snap nomatch # ... and asking for `zqm` AGAIN re-arms the list it ALREADY filled instead of diff --git a/test/snapshots/fsearch.snap b/test/snapshots/fsearch.snap index b050f1db..431e7126 100644 --- a/test/snapshots/fsearch.snap +++ b/test/snapshots/fsearch.snap @@ -49,16 +49,16 @@ snap results snapstyle results # n/N walk on from there, one row of the list per press, Enter looking what # the step selected -key n +key space j n key enter stable 700 15000 snap second -key n +key space j n key enter stable 700 15000 snap third # N walks back up to result 2 (line 6), Enter looks it -key N +key space j p key enter stable 700 15000 snap back @@ -75,6 +75,6 @@ key / text zzqq key enter stable 700 10000 -key n +key space j n stable 400 5000 snap nomatch diff --git a/test/snapshots/grep.snap b/test/snapshots/grep.snap index 07777e67..b3ce2947 100644 --- a/test/snapshots/grep.snap +++ b/test/snapshots/grep.snap @@ -55,16 +55,16 @@ stable 700 15000 snap results # n selects the first row and Enter looks it: absolute path, line 1, columns # 7..12 (`TARGET`), and those six cells come up selected -key n +key space j n key enter stable 700 15000 snap first # ...and stepping on into sub/b.txt, then looking it, opens the file nothing # had open -key n +key space j n key enter stable 700 15000 -key n +key space j n key enter wait 10000 TARGET inside sub stable 700 15000 @@ -88,7 +88,7 @@ stable 400 5000 text zzqq key enter stable 700 10000 -key n +key space j n stable 400 5000 snap nomatch # the acme chord: a builtin executed with a SELECTION held takes it as the diff --git a/test/snapshots/jumps.snap b/test/snapshots/jumps.snap index 9ba0139d..f8d69d2a 100644 --- a/test/snapshots/jumps.snap +++ b/test/snapshots/jumps.snap @@ -85,26 +85,26 @@ snap jumplist # An `@pN` row moves focus like any other, which it did not use to: the STEP # only selects now, and the look Enter runs goes to the pane by the same route # a path takes. -key n +key space j n key enter stable 700 15000 snap step1-shell snapstyle step1-shell # on to row 2 — one press, the directory on row 1 is no longer a stop of its own -key n +key space j n key enter stable 700 15000 snap step2-file # row 3 is the shell again, then row 4 -key n +key space j n stable 400 5000 -key n +key space j n key enter stable 700 15000 snap step4-line100 # N is the exact inverse: one press back onto row 3's location, and Enter # follows it to the shell -key N +key space j p key enter stable 700 15000 snap step-back diff --git a/test/snapshots/lookrange.snap b/test/snapshots/lookrange.snap index 50ef9ad3..eb1db60a 100644 --- a/test/snapshots/lookrange.snap +++ b/test/snapshots/lookrange.snap @@ -65,13 +65,13 @@ stable 700 15000 snap hit1 snapstyle hit1 # n selects the next row, and the Enter after it goes to that hit -key n +key space j n key enter stable 700 15000 snap hit2 snapstyle hit2 # N walks back onto the first hit; Enter looks it, still selected -key N +key space j p key enter stable 700 15000 snap back diff --git a/test/snapshots/lsp-client.snap b/test/snapshots/lsp-client.snap index 541e7c7f..db94525e 100644 --- a/test/snapshots/lsp-client.snap +++ b/test/snapshots/lsp-client.snap @@ -27,11 +27,11 @@ wait 10000 add(3, 4) stable 700 15000 snap gr-list # step from the selected middle row to the last hit, then return -key n +key space j n key enter stable 700 15000 snap gr-opened -key N +key space j p key enter stable 700 15000 snap gr-back diff --git a/test/snapshots/lsp.snap b/test/snapshots/lsp.snap index 97fcf7ed..123fad93 100644 --- a/test/snapshots/lsp.snap +++ b/test/snapshots/lsp.snap @@ -43,7 +43,7 @@ key l key s stable 700 15000 snap symbols -key n +key space j n key enter stable 700 15000 snap step diff --git a/test/snapshots/lspcomplete.snap b/test/snapshots/lspcomplete.snap index e25c6525..5c76aac8 100644 --- a/test/snapshots/lspcomplete.snap +++ b/test/snapshots/lspcomplete.snap @@ -93,7 +93,7 @@ settle 100 # jump the way a goto with one row does. The first step selects row 1, and the # Enter after it looks that row and lands SELECTING `verdigris` on line 2 of # a.zig. -key n +key space j n key enter stable 700 15000 snap step diff --git a/test/snapshots/lsprelpath.snap b/test/snapshots/lsprelpath.snap index 667c2fc8..a83abf46 100644 --- a/test/snapshots/lsprelpath.snap +++ b/test/snapshots/lsprelpath.snap @@ -46,7 +46,7 @@ key esc settle 100 # An absolute row has to keep resolving — it is the spelling every row had # before this, and the one every hit outside the tree still has. -key n +key space j n key enter stable 700 15000 snap abslook @@ -65,7 +65,7 @@ stable 700 15000 snap subrow key esc settle 100 -key n +key space j n key enter stable 700 15000 snap sublook diff --git a/test/snapshots/psearch.snap b/test/snapshots/psearch.snap index 6e463119..d55fe833 100644 --- a/test/snapshots/psearch.snap +++ b/test/snapshots/psearch.snap @@ -41,12 +41,12 @@ stable 700 15000 snap results snapstyle results # n walks on to the next row, Enter looks it -key n +key space j n key enter stable 700 15000 snap second # N walks back one row, Enter looks it -key N +key space j p key enter stable 700 15000 snap back @@ -58,7 +58,7 @@ key / text zzqq key enter stable 700 10000 -key n +key space j n stable 400 5000 snap nomatch # right-clicking a word that names no file is the same search (acme button 3), diff --git a/test/snapshots/stepgrain.snap b/test/snapshots/stepgrain.snap index 3c4d3e4c..0f555ff8 100644 --- a/test/snapshots/stepgrain.snap +++ b/test/snapshots/stepgrain.snap @@ -36,21 +36,21 @@ wait 10000 sub/b.txt:1:1 stable 700 15000 snap results # one press, one row: the head of row 1... -key n +key space j n stable 400 5000 snap step-row1 snapstyle step-row1 # ...the head of row 2, and NOT the `sub/b.txt` sitting in its matched text — # the cursor column is the assertion -key n +key space j n stable 400 5000 snap step-row2 snapstyle step-row2 # ...row 3, and then the ring comes round to row 1 again -key n +key space j n stable 400 5000 snap step-row3 -key n +key space j n stable 400 5000 snap step-wrap # Back into the file, so the Find below is asked from a pane that is not a @@ -68,7 +68,7 @@ text words key enter wait 10000 two words.txt stable 700 15000 -key n +key space j n stable 400 5000 snap blank-in-path snapstyle blank-in-path diff --git a/test/snapshots/themesel.snap b/test/snapshots/themesel.snap index 1d61bf6a..4c4d2baa 100644 --- a/test/snapshots/themesel.snap +++ b/test/snapshots/themesel.snap @@ -31,53 +31,53 @@ snap list # n selects row 1 whole and Tab runs it: `Theme orchard`, which is already the # boot theme, so only the selection moves. That is the honest first step — an # idempotent command has to be safe to run. -key n +key space j n key tab stable 700 15000 snap step-orchard snapstyle step-orchard # ...and now the theme really does change under the cursor, one row at a time -key n +key space j n key tab stable 700 15000 snap step-dusk snapstyle step-dusk # Selection alone can skip rows without previewing or applying their themes. # Four steps reach atelier, the Acme homage; Tab then applies it. -key n -key n -key n -key n +key space j n +key space j n +key space j n +key space j n key tab stable 700 15000 snap step-atelier snapstyle step-atelier -key n +key space j n key tab stable 700 15000 snap step-forge snapstyle step-forge -key n +key space j n key tab stable 700 15000 snap step-lagoon snapstyle step-lagoon -key n +key space j n key tab stable 700 15000 snap step-solarium snapstyle step-solarium -key n +key space j n key tab stable 700 15000 snap step-spectrum snapstyle step-spectrum -key n +key space j n key tab stable 700 15000 snap step-harvest snapstyle step-harvest -key n +key space j n key tab stable 700 15000 snap step-clay @@ -85,37 +85,37 @@ snapstyle step-clay # The three native contrast variants precede acme, lapis and lapis_plain, and then the first # ported family's section. Its heading # and blank separator are not stops in the n/N command walk. -key n +key space j n key tab stable 700 15000 snap step-forge-black snapstyle step-forge-black -key n +key space j n key tab stable 700 15000 snap step-forge-soft snapstyle step-forge-soft -key n +key space j n key tab stable 700 15000 snap step-orchard-black snapstyle step-orchard-black -key n +key space j n key tab stable 700 15000 snap step-acme snapstyle step-acme -key n +key space j n key tab stable 700 15000 snap step-lapis snapstyle step-lapis -key n +key space j n key tab stable 700 15000 snap step-lapis-plain snapstyle step-lapis-plain -key n +key space j n key tab stable 700 15000 snap step-dark-plus @@ -124,14 +124,14 @@ snapstyle step-dark-plus # its blank line are skipped like the first. (The imported half, past the # legacy section, is sorted by name, so the ring is the same everywhere # whatever order the directory read handed the files over in.) -key n +key space j n key tab stable 700 15000 snap step-solarized-dark snapstyle step-solarized-dark # N walks back the same way — it is the exact inverse of n — and the Tab after # it runs the row it lands on, so the theme rewinds too -key N +key space j p key tab stable 700 15000 snap step-back diff --git a/test/snapshots/ttylook.snap b/test/snapshots/ttylook.snap index 91401a64..62760ae6 100644 --- a/test/snapshots/ttylook.snap +++ b/test/snapshots/ttylook.snap @@ -17,16 +17,16 @@ wait 8000 big.txt stable 700 20000 # first n: cursor sits at the shell prompt below the output — wrap lands on # the ls row's first token, big.txt; nothing opens -key n +key space j n stable 400 5000 snap tok1 snapstyle tok1 # same row, next token: plain.txt -key n +key space j n stable 400 5000 snap tok2 # N steps back to big.txt -key N +key space j p stable 400 5000 snap tokback # insert-mode n still types (a run splice), no stepping; undo it @@ -39,9 +39,9 @@ snap insert key u stable 400 5000 # resume the walk from big.txt's start: plain.txt, then sub -key n +key space j n stable 400 5000 -key n +key space j n stable 400 5000 snap tok3 # Return looks the selected dir: a shell opens below in sub and ls's it @@ -52,7 +52,7 @@ snap diropen # spined on the panes that have LOOKED, so the step leaves this shell for the # one it was looked out of. That pane's cursor is on its last token (`sub`), # so the walk runs off the end and comes round to its first — big.txt. -key n +key space j n stable 400 5000 snap noop # back in the first pane, Enter with the cursor ON a token looks it (no |
