summaryrefslogtreecommitdiff
path: root/src/modal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-08 12:00:28 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:15 -0300
commit13d5613b77c62c425c3a124a34c0c2528cc6251f (patch)
treef3cbe41683ef31641ea087039db9fc3be81e141f /src/modal.zig
parent046979b877f02a91cf52cc86b84c5619cb9363d3 (diff)
downloadpardes-13d5613b77c62c425c3a124a34c0c2528cc6251f.tar.gz
pardes-13d5613b77c62c425c3a124a34c0c2528cc6251f.zip
Follow Helix search registers for n/N; keep Look navigation as named builtins
Diffstat (limited to 'src/modal.zig')
-rw-r--r--src/modal.zig23
1 files changed, 20 insertions, 3 deletions
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;
}