summaryrefslogtreecommitdiff
path: root/src/normal.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/normal.zig')
-rw-r--r--src/normal.zig30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/normal.zig b/src/normal.zig
index c7e75d70..ffbb49d5 100644
--- a/src/normal.zig
+++ b/src/normal.zig
@@ -67,13 +67,13 @@ pub fn multiOnce(p: *Pardes) bool {
return p.multi_first;
}
-fn startSelRegex(p: *Pardes, pane: *Pane, split: bool) void {
- const text = edit.flatSurface(p, &pane.body) catch return;
- const got = pane.body.ranges(text, 0, &pane.sel_snap);
+fn startSelRegex(p: *Pardes, pane: *Pane, t: *Text, split: bool) void {
+ const text = edit.flatSurface(p, t) catch return;
+ const got = t.ranges(text, 0, &pane.sel_snap);
pane.nsel_snap = @intCast(got.n);
pane.sel_snap_pri = @intCast(got.pri);
- pane.sel_snap_expl = (pane.body.vsel.active and pane.body.vsel.explicit) or pane.body.msel.active;
- p.startPrompt(pane, .{ .search = if (split) config.split_marker else config.select_marker });
+ pane.sel_snap_expl = (t.vsel.active and t.vsel.explicit) or t.msel.active;
+ p.startPrompt(pane, t, .{ .search = if (split) config.split_marker else config.select_marker });
}
pub fn selRegexArmed(pane: *Pane) ?struct { pat: []const u8, split: bool } {
@@ -85,8 +85,10 @@ pub fn selRegexArmed(pane: *Pane) ?struct { pat: []const u8, split: bool } {
return .{ .pat = armed[slash + 1 ..], .split = split };
}
-pub fn applySelRegex(p: *Pardes, pane: *Pane, pat: []const u8, split: bool) void {
- const text = edit.flatSurface(p, &pane.body) catch return;
+/// Select (or split on) `pat` inside the selections `t` had when s/S was
+/// pressed; the prompt's snapshot of them lives on `pane`.
+pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, split: bool) void {
+ const text = edit.flatSurface(p, t) catch return;
const snap = pane.sel_snap[0..pane.nsel_snap];
var out: [Text.max_selections]modal.Selection = undefined;
var m: usize = 0;
@@ -132,9 +134,9 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, pat: []const u8, split: bool) void
r.anchor = @min(r.anchor, text.len);
r.head = @min(r.head, text.len);
}
- return pane.body.setRanges(text, snap, &.{}, pane.sel_snap_pri, pane.sel_snap_expl);
+ return t.setRanges(text, snap, &.{}, pane.sel_snap_pri, pane.sel_snap_expl);
}
- pane.body.setRanges(text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO)
+ t.setRanges(text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO)
}
const KeyState = struct {
@@ -521,7 +523,9 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void
}
return t.multiSelAction(text, multi.kind, multi.count);
},
- .select_regex => |split| return startSelRegex(p, pane, split),
+ // s, S and | answer for the text they are pressed in; `/` searches
+ // the body wherever it is pressed, as acme's Look from a tag does.
+ .select_regex => |split| return startSelRegex(p, pane, t, split),
.edit => |op| switch (op.kind) {
.delete => return edit.normalDelete(p, t, true),
.delete_noyank => return edit.normalDelete(p, t, false),
@@ -560,8 +564,8 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void
.column, .workspace => tagline.exitHeader(p),
.body, .input => tagline.enterTag(p, pane),
},
- .pipe_selection => |how| return p.startPrompt(pane, .{ .pipe = how }),
- .search => return p.startPrompt(pane, .{ .search = config.search_marker }),
+ .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,
@@ -602,7 +606,7 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void {
p.leader_n = 0;
},
.command_line => tagline.enterTag(p, pane),
- .search => p.startPrompt(pane, .{ .search = config.search_marker }),
+ .search => p.startPrompt(pane, &pane.body, .{ .search = config.search_marker }),
.search_forward => look.lookWalk(p, 1),
.search_backward => look.lookWalk(p, -1),
}