refactor: move cut_to helix workaround to a helix specific command

This commit is contained in:
CJ van den Berg 2025-04-03 06:35:07 +02:00
parent 62c6313107
commit 563eb57e44
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 16 additions and 10 deletions

View file

@ -146,8 +146,8 @@
["a", ["move_right"], ["enter_mode", "insert"]], ["a", ["move_right"], ["enter_mode", "insert"]],
["o", ["smart_insert_line_after"], ["enter_mode", "insert"]], ["o", ["smart_insert_line_after"], ["enter_mode", "insert"]],
["d", "cut_forward_internal"], ["d", "cut_forward_internal_inclusive"],
["c", ["cut_forward_internal"], ["enter_mode", "insert"]], ["c", ["cut_forward_internal_inclusive"], ["enter_mode", "insert"]],
["s", "select_regex"], ["s", "select_regex"],
[";", "collapse_selections"], [";", "collapse_selections"],

View file

@ -2495,14 +2495,7 @@ pub const Editor = struct {
continue; continue;
} }
switch (tui.get_selection_style()) { with_selection_const(root, move, cursel, self.metrics) catch continue;
.inclusive => {
const sel = try cursel.enable_selection(root, self.metrics);
cursel.cursor = sel.end;
cursel.check_selection(root, self.metrics);
},
else => with_selection_const(root, move, cursel, self.metrics) catch continue,
}
const cut_text, root = self.cut_selection(root, cursel) catch continue; const cut_text, root = self.cut_selection(root, cursel) catch continue;
if (first) { if (first) {

View file

@ -124,6 +124,17 @@ const cmds_ = struct {
ed.clamp(); ed.clamp();
} }
pub const move_prev_word_start_meta: Meta = .{ .description = "Move previous word start" }; pub const move_prev_word_start_meta: Meta = .{ .description = "Move previous word start" };
pub fn cut_forward_internal_inclusive(_: *void, _: Ctx) Result {
const mv = tui.mainview() orelse return;
const ed = mv.get_active_editor() orelse return;
const b = try ed.buf_for_update();
const text, const root = try ed.cut_to(move_noop, b.root);
ed.set_clipboard_internal(text);
try ed.update_buf(root);
ed.clamp();
}
pub const cut_forward_internal_inclusive_meta: Meta = .{ .description = "Cut next character to internal clipboard (inclusive)" };
}; };
fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
@ -148,3 +159,5 @@ fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buff
try move_cursor_word_left_helix(root, cursor, metrics); try move_cursor_word_left_helix(root, cursor, metrics);
} }
} }
fn move_noop(_: Buffer.Root, _: *Cursor, _: Buffer.Metrics) error{Stop}!void {}