diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 20:33:01 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 20:33:01 -0300 |
| commit | abe3817e8dd0af41e6b5786bdbeb631219b58c23 (patch) | |
| tree | d2db2ba07f1b8ee743926aa87b8c25070f72fcb6 /core/normal.zig | |
| parent | 480f36b85299fa7407c20a2d6482dd093f842bf7 (diff) | |
| download | pardes-abe3817e8dd0af41e6b5786bdbeb631219b58c23.tar.gz pardes-abe3817e8dd0af41e6b5786bdbeb631219b58c23.zip | |
Prompt: a body's text prompts ask in its tag's head (walk UI, pick-ui SPEC.md §7.1, §7.2, item 1 of line E): `s S K A-K | A-| ! A-! $` from a body are a typing state of the view's tag (TagState.Kind.prompt, its state Prompt.zig, its field A's Field), drawn after the prefix in place of the tag's own text (R1): box `^`, the prompt's key cell, the field, the plain word it stands for (`= Exec Edit x/self/`, `Edit g/re/`, `Edit |tr a-z A-Z`, `Edit >cmd`; none for `! A-! $`), its count (`2 selections in 3 lines`, `keeps 1 of 2`, `0` for no match, the selections it began with back), the hints; the live machinery as it was (normal.applySelRegex, now returning what it found; the pipe off the loop, Pipe.submit split from the notice band's submitPipe); a pattern that is no regex changes nothing, the last result drawn dimmed (body_layer) and the reason at the count's place in the error ink (TagState.Style.err, regexp's message); Up/Down recall the history inline, Ctrl-r unrolls it as a band step filtered by the field (three session histories, Pardes.prompt_history: search and select's, the pipes', the command line's, 16 lines each, in the digest and the dump); Esc and Backspace on an empty field put the body back; Enter keeps the line in its history and the pattern in `/`, the command in `|`; a paste goes into the field; a prompt for a tag's or a header's text, Save's path, a terminal's `/` still ask on the notice band; wire 37; TEST FIRST: Prompt.zig "s asks in the tag's head ..." and "Enter keeps what s found ... a pipe from the body asks in the tag and runs off the loop"; Pipe.zig's and panes.zig's prompt tests and test/behaviour/keys.zig's two read the head; goldens pipe, selregex, msg (the prompt in the tag head, no chip); core-test 1014/1180 (166 skipped), shell-test 1227/1230, pane-test 182/184 (the 1 failure A's: `SPC h ?` is Help in the tag now), behaviour-test 274/277 (the 3 failures A's: window mode's head, a struck leader key), process-test the 6 of A's report plus none of mine, term-test 17/17, kitty-test 45/45
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/normal.zig')
| -rw-r--r-- | core/normal.zig | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/core/normal.zig b/core/normal.zig index 1f7ce1a7..c59a847c 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -22,6 +22,7 @@ const sel_slot = pardes.sel_slot; const Pardes = pardes.Pardes; const Macro = pardes.Macro; const Editor = @import("Editor.zig"); +const Prompt = @import("Prompt.zig"); fn isPrefix(key: Key, cp: u21) bool { return key.cp == cp and !key.ctrl and !key.alt; @@ -53,15 +54,19 @@ pub fn selRegexArmed(pane: *Pane) ?struct { pat: []const u8, mode: modal.Normal. /// Select (or split on, keep or remove by) `pat` inside the selections `t` /// had when s/S/K/Alt-K was pressed; the prompt's snapshot of them lives on -/// `pane`. -pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: modal.Normal.RegexMode) void { - selectByRegex(p.editor(), t, pane.sel_snap[0..pane.nsel_snap], pane.sel_snap_pri, pane.sel_snap_expl, pat, mode); +/// `pane`. The ranges it found: none, the snapshot's back. +pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: modal.Normal.RegexMode) usize { + return selectByRegex(p.editor(), t, pane.sel_snap[0..pane.nsel_snap], pane.sel_snap_pri, pane.sel_snap_expl, pat, mode); } /// Select (or split on, keep or remove by) `pat` inside `snap`, the -/// ranges there were (primary `pri`) when s/S/K/Alt-K was pressed. -pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, expl: bool, pat: []const u8, mode: modal.Normal.RegexMode) void { - const text = edit.flatSurface(e, t) catch |err| return e.reportError(err); +/// ranges there were (primary `pri`) when s/S/K/Alt-K was pressed; the +/// ranges it found. +pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, expl: bool, pat: []const u8, mode: modal.Normal.RegexMode) usize { + const text = edit.flatSurface(e, t) catch |err| { + e.reportError(err); + return 0; + }; var out: [Text.max_selections]modal.Selection = undefined; var m: usize = 0; if (regexp.Regex.compile(pat)) |compiled| { @@ -69,7 +74,10 @@ pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, e var hay_all = text; if (for (pat) |c| { if (std.ascii.isUpper(c)) break false; - } else true) hay_all = std.ascii.allocLowerString(e.scratch, text) catch |err| return e.reportError(err); + } else true) hay_all = std.ascii.allocLowerString(e.scratch, text) catch |err| { + e.reportError(err); + return 0; + }; for (snap) |r| { const from = @min(r.anchor, r.head); const to = @min(@max(r.anchor, r.head), text.len); @@ -116,9 +124,11 @@ pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, e r.anchor = @min(r.anchor, text.len); r.head = @min(r.head, text.len); } - return t.setRanges(e.tab, text, snap, &.{}, pri, expl); + t.setRanges(e.tab, text, snap, &.{}, pri, expl); + return 0; } t.setRanges(e.tab, text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO) + return m; } fn lastMatch(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { @@ -600,6 +610,9 @@ fn actionPass(e: Editor, t: *Text, action: modal.Normal.Action) edit.Error!void } fn startSelRegex(p: *Pardes, pane: *Pane, t: *Text, mode: modal.Normal.RegexMode) edit.Error!void { + // A body's prompt is its tag's (Prompt.zig); a tag's or a header's asks + // on the notice band. + if (t.what == .body) return Prompt.open(p, pane, Prompt.ofMode(mode)); const text = try edit.flatSurface(p.editor(), t); const got = t.ranges(text, 0, &pane.sel_snap); pane.nsel_snap = @intCast(got.n); @@ -1360,11 +1373,18 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! .column, .workspace => tagline.exitHeader(p), .body, .input => tagline.enterTag(p, pane), }, - .pipe_selection => return panes.startPrompt(p, pane, t, .{ .pipe = .replace }), - .pipe_selection_to => return panes.startPrompt(p, pane, t, .{ .pipe = .ignore }), - .insert_output => return panes.startPrompt(p, pane, t, .{ .pipe = .insert }), - .append_output => return panes.startPrompt(p, pane, t, .{ .pipe = .append }), - .keep_pipe => return panes.startPrompt(p, pane, t, .{ .pipe = .keep }), + inline .pipe_selection, .pipe_selection_to, .insert_output, .append_output, .keep_pipe => |role| { + const how: modal.Normal.PipeBehavior = switch (role) { + .pipe_selection => .replace, + .pipe_selection_to => .ignore, + .insert_output => .insert, + .append_output => .append, + else => .keep, + }; + // A body's in its tag (Prompt.zig), else on the notice band. + if (t.what == .body) return Prompt.open(p, pane, Prompt.ofBehavior(how)); + return panes.startPrompt(p, pane, t, .{ .pipe = how }); + }, // `/` in a text is its query pane's line 1 (Query.zig); a // terminal's still asks on the notice band. .search => if (pane.file != null and t.what == .body) @@ -1657,7 +1677,7 @@ test "s and S search a multi-line selection as addr does: ^ and $ per line, . wi }) |c| { pane.sel_snap[0] = .{ .anchor = 0, .head = text.len }; pane.nsel_snap = 1; - applySelRegex(p, pane, &pane.body, c.pat, c.mode); + _ = applySelRegex(p, pane, &pane.body, c.pat, c.mode); var out: [Text.max_selections]modal.Selection = undefined; const got = pane.body.ranges(text, 0, &out); try std.testing.expectEqual(c.want.len, got.n); |
