diff options
Diffstat (limited to 'src/modal.zig')
| -rw-r--r-- | src/modal.zig | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/modal.zig b/src/modal.zig index 316a66fa..82f1a3a0 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -36,6 +36,7 @@ pub const Normal = struct { goto_type_definition, goto_implementation, goto_references, + goto_callstack, view_top, view_center, @@ -157,10 +158,12 @@ pub const Normal = struct { search, search_next, search_prev, + search_selection, + search_selection_word, }; pub const Input = struct { - roles: std.EnumSet(Role) = .initEmpty(), + roles: std.EnumSet(Role) = .empty, cp: u21, ctrl: bool = false, alt: bool = false, @@ -318,7 +321,7 @@ pub const Normal = struct { undo, redo, }; - pub const Lsp = enum { definition, declaration, type_definition, implementation, references, format }; + pub const Lsp = enum { definition, declaration, type_definition, implementation, references, callstack, format }; pub const Counted = struct { count: u32, @@ -355,7 +358,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 +377,7 @@ pub const Normal = struct { .pipe_selection, .search, .search_step, + .search_selection, .macro_record, .macro_replay, .node, @@ -467,6 +472,7 @@ pub const Normal = struct { if (key.has(.goto_type_definition)) return resultAction(.{ .lsp = .type_definition }); if (key.has(.goto_implementation)) return resultAction(.{ .lsp = .implementation }); if (key.has(.goto_references)) return resultAction(.{ .lsp = .references }); + if (key.has(.goto_callstack)) return resultAction(.{ .lsp = .callstack }); return .ignored; }, .view => { @@ -676,8 +682,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 +1428,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; } |
