From 7a1a411aafaff37515cbbad960754706757f9c25 Mon Sep 17 00:00:00 2001 From: Levi Date: Tue, 8 Apr 2025 14:23:56 -0300 Subject: [PATCH 1/2] feat: Helix mode: move_next_word_end (#223) * Helix mode: move_next_word_end * fix: don't match against legacy unshifted keys when we have extended input text closes #205 * refactor: remove duplicate implementation of command.get_id * feat: re-add support for integer command arguments closes #182 * feat: display pending integer argument in keybind widget * fix: call configured init_commands for all mode types * feat: add flow mode keybindings for setting integer argument * feat: add support for repeat integer arguments to many commands * feat: add emacs mode keybindings for setting integer argument * feat: add vim mode keybindings for setting integer argument * resolving conflit * disable_selection --------- Co-authored-by: CJ van den Berg --- src/tui/editor.zig | 2 +- src/tui/mode/helix.zig | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 5790736..3195b19 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -129,7 +129,7 @@ pub const CurSel = struct { return res; } - fn disable_selection(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) void { + pub fn disable_selection(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) void { switch (tui.get_selection_style()) { .normal => self.disable_selection_normal(), .inclusive => self.disable_selection_inclusive(root, metrics), diff --git a/src/tui/mode/helix.zig b/src/tui/mode/helix.zig index e0d0e88..0611d64 100644 --- a/src/tui/mode/helix.zig +++ b/src/tui/mode/helix.zig @@ -110,7 +110,6 @@ const cmds_ = struct { ed.with_selections_const_repeat(root, Editor.move_cursor_word_right_vim, ctx) catch {}; ed.clamp(); } - pub const move_next_word_start_meta: Meta = .{ .description = "Move next word start", .arguments = &.{.integer} }; pub fn move_prev_word_start(_: *void, ctx: Ctx) Result { @@ -127,6 +126,21 @@ const cmds_ = struct { } pub const move_prev_word_start_meta: Meta = .{ .description = "Move previous word start", .arguments = &.{.integer} }; + pub fn move_next_word_end(_: *void, _: Ctx) Result { + const mv = tui.mainview() orelse return; + const ed = mv.get_active_editor() orelse return; + const root = try ed.buf_root(); + + for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { + cursel.disable_selection(root, ed.metrics); + }; + + ed.with_selections_const(root, Editor.move_cursor_word_right_end_vim) catch {}; + ed.with_selections_const(root, Editor.move_cursor_right) catch {}; + ed.clamp(); + } + pub const move_next_word_end_meta: Meta = .{ .description = "Move next word end" }; + pub fn cut_forward_internal_inclusive(_: *void, _: Ctx) Result { const mv = tui.mainview() orelse return; const ed = mv.get_active_editor() orelse return; From 41339b05e4fecd9fe38a737706b1a21eac6d6f1f Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 8 Apr 2025 19:32:00 +0200 Subject: [PATCH 2/2] fix: merge build failure in helix.move_next_word_end and add repeat support --- src/tui/editor.zig | 4 ++-- src/tui/mode/helix.zig | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 3195b19..d4e80ff 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -2073,7 +2073,7 @@ pub const Editor = struct { return false; } - fn is_word_boundary_right_vim(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool { + pub fn is_word_boundary_right_vim(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool { if (is_whitespace_at_cursor(root, cursor, metrics)) return false; var next = cursor.*; next.move_right(root, metrics) catch return true; @@ -2155,7 +2155,7 @@ pub const Editor = struct { try cursor.move_right(root, metrics); } - fn move_cursor_right_until(root: Buffer.Root, cursor: *Cursor, pred: cursor_predicate, metrics: Buffer.Metrics) void { + pub fn move_cursor_right_until(root: Buffer.Root, cursor: *Cursor, pred: cursor_predicate, metrics: Buffer.Metrics) void { while (!pred(root, cursor, metrics)) move_cursor_right(root, cursor, metrics) catch return; } diff --git a/src/tui/mode/helix.zig b/src/tui/mode/helix.zig index 0611d64..46a9880 100644 --- a/src/tui/mode/helix.zig +++ b/src/tui/mode/helix.zig @@ -126,7 +126,7 @@ const cmds_ = struct { } pub const move_prev_word_start_meta: Meta = .{ .description = "Move previous word start", .arguments = &.{.integer} }; - pub fn move_next_word_end(_: *void, _: Ctx) Result { + pub fn move_next_word_end(_: *void, ctx: Ctx) Result { const mv = tui.mainview() orelse return; const ed = mv.get_active_editor() orelse return; const root = try ed.buf_root(); @@ -135,11 +135,10 @@ const cmds_ = struct { cursel.disable_selection(root, ed.metrics); }; - ed.with_selections_const(root, Editor.move_cursor_word_right_end_vim) catch {}; - ed.with_selections_const(root, Editor.move_cursor_right) catch {}; + ed.with_selections_const_repeat(root, move_cursor_word_right_end_helix, ctx) catch {}; ed.clamp(); } - pub const move_next_word_end_meta: Meta = .{ .description = "Move next word end" }; + pub const move_next_word_end_meta: Meta = .{ .description = "Move next word end", .arguments = &.{.integer} }; pub fn cut_forward_internal_inclusive(_: *void, _: Ctx) Result { const mv = tui.mainview() orelse return; @@ -252,3 +251,9 @@ fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buff } fn move_noop(_: Buffer.Root, _: *Cursor, _: Buffer.Metrics) error{Stop}!void {} + +fn move_cursor_word_right_end_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { + try Editor.move_cursor_right(root, cursor, metrics); + Editor.move_cursor_right_until(root, cursor, Editor.is_word_boundary_right_vim, metrics); + try cursor.move_right(root, metrics); +}