diff --git a/src/tui/editor.zig b/src/tui/editor.zig index a5db341..4f34ae3 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -103,7 +103,7 @@ pub const CurSel = struct { }; } - fn enable_selection_normal(self: *Self) *Selection { + pub fn enable_selection_normal(self: *Self) *Selection { return if (self.selection) |*sel| sel else cod: { @@ -501,7 +501,7 @@ pub const Editor = struct { return self.buffer orelse error.Stop; } - fn buf_root(self: *const Self) !Buffer.Root { + pub fn buf_root(self: *const Self) !Buffer.Root { return if (self.buffer) |p| p.root else error.Stop; } @@ -1649,7 +1649,7 @@ pub const Editor = struct { self.view.col = dest.col; } - inline fn clamp(self: *Self) void { + pub inline fn clamp(self: *Self) void { self.clamp_abs(false); } @@ -2101,7 +2101,7 @@ pub const Editor = struct { move_cursor_left(root, cursor, metrics) catch return; } - fn move_cursor_begin(_: Buffer.Root, cursor: *Cursor, _: Buffer.Metrics) !void { + pub fn move_cursor_begin(_: Buffer.Root, cursor: *Cursor, _: Buffer.Metrics) !void { cursor.move_begin(); } @@ -2124,7 +2124,7 @@ pub const Editor = struct { move_cursor_right(root, cursor, metrics) catch return; } - fn move_cursor_end(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) !void { + pub fn move_cursor_end(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) !void { cursor.move_end(root, metrics); } diff --git a/src/tui/mode/helix.zig b/src/tui/mode/helix.zig index db27f14..6838af5 100644 --- a/src/tui/mode/helix.zig +++ b/src/tui/mode/helix.zig @@ -5,6 +5,7 @@ const command = @import("command"); const cmd = command.executeName; const tui = @import("../tui.zig"); +const Editor = @import("../editor.zig").Editor; var commands: Commands = undefined; @@ -72,4 +73,24 @@ const cmds_ = struct { }, sel); } pub const save_selection_meta: Meta = .{ .description = "Save current selection to location history" }; + + pub fn extend_line_below(_: *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| { + const sel = cursel.enable_selection_normal(); + sel.normalize(); + + try Editor.move_cursor_begin(root, &sel.begin, ed.metrics); + try Editor.move_cursor_end(root, &sel.end, ed.metrics); + cursel.cursor = sel.end; + try cursel.selection.?.end.move_right(root, ed.metrics); + try cursel.cursor.move_right(root, ed.metrics); + }; + + ed.clamp(); + } + pub const extend_line_below_meta: Meta = .{ .description = "Select current line, if already selected, extend to next line" }; };