summaryrefslogtreecommitdiff
path: root/src/normal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 10:29:10 -0300
committerGabriel Schneider <[email protected]>2026-10-24 10:29:10 -0300
commit18d89dcedaed1f8437799621675e88ca47d7cdc1 (patch)
tree2cf2e2ae46de1308e5b90aca33413282cdd73e8b /src/normal.zig
parent873f81ccb1449119846de8d4e6e0e8899236100a (diff)
downloadpardes-18d89dcedaed1f8437799621675e88ca47d7cdc1.tar.gz
pardes-18d89dcedaed1f8437799621675e88ca47d7cdc1.zip
Search converge 2/6: a pane's places, every match or listed place tinted and ticked on the rail, n/N stepping them silently, shifted by an edit rather than searched again
Diffstat (limited to 'src/normal.zig')
-rw-r--r--src/normal.zig30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/normal.zig b/src/normal.zig
index 8de23d1c..808ac886 100644
--- a/src/normal.zig
+++ b/src/normal.zig
@@ -256,18 +256,20 @@ pub fn searchSelection(p: *Pardes, t: *Text, text: []const u8, boundary: bool) v
}
// mvzr's word boundary is ASCII-only. Strip outer boundaries and check
-// them against Unicode characters for search-selection patterns.
-const SearchRegex = struct {
+// them against Unicode characters for search-selection patterns. A pane's
+// Places keep one of these, compiled with the gpa, for as long as they live.
+pub 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 {
+ pub 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;
+ errdefer branches.deinit(arena);
var from: usize = 0;
var depth: usize = 0;
var escaped = false;
@@ -291,7 +293,7 @@ const SearchRegex = struct {
}
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 };
+ return .{ .branches = try branches.toOwnedSlice(arena) };
}
fn branch(pattern: []const u8) !Branch {
@@ -303,7 +305,7 @@ const SearchRegex = struct {
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 {
+ pub 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;
@@ -929,8 +931,22 @@ 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 => |step| return searchStep(p, t, text, step.direction, step.count),
- .search_selection => |boundary| return searchSelection(p, t, text, boundary),
+ // In a file's text, n and N step its places while they answer for
+ // the register (Places.answersN); else helix's search of the register.
+ .search_step => |step| if (t.what == .body and pane.file != null and pane.places.answersN(p, pane))
+ return pane.places.step(p, pane, step.direction == .forward, step.count, t.select)
+ else
+ return searchStep(p, t, text, step.direction, step.count),
+ .search_selection => |boundary| {
+ searchSelection(p, t, text, boundary);
+ // The pattern's places: the selection is already on one of them.
+ if (t.what == .body and pane.file != null) {
+ const name = if (p.register != 0) p.register else '/';
+ const pat = p.registers.value(name, 0) orelse return;
+ const r = pane.body.primaryRange(text, 0);
+ pane.places.search(p, pane, .search, 0, pat, false, @min(r.anchor, r.head), false);
+ }
+ },
.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),