Helix mode: adding extend_line_below

This commit is contained in:
Levi Santos 2025-03-30 13:39:01 -03:00 committed by CJ van den Berg
parent b30a5d4819
commit b850befc5d
2 changed files with 26 additions and 5 deletions

View file

@ -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| return if (self.selection) |*sel|
sel sel
else cod: { else cod: {
@ -501,7 +501,7 @@ pub const Editor = struct {
return self.buffer orelse error.Stop; 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; return if (self.buffer) |p| p.root else error.Stop;
} }
@ -1649,7 +1649,7 @@ pub const Editor = struct {
self.view.col = dest.col; self.view.col = dest.col;
} }
inline fn clamp(self: *Self) void { pub inline fn clamp(self: *Self) void {
self.clamp_abs(false); self.clamp_abs(false);
} }
@ -2101,7 +2101,7 @@ pub const Editor = struct {
move_cursor_left(root, cursor, metrics) catch return; 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(); cursor.move_begin();
} }
@ -2124,7 +2124,7 @@ pub const Editor = struct {
move_cursor_right(root, cursor, metrics) catch return; 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); cursor.move_end(root, metrics);
} }

View file

@ -5,6 +5,7 @@ const command = @import("command");
const cmd = command.executeName; const cmd = command.executeName;
const tui = @import("../tui.zig"); const tui = @import("../tui.zig");
const Editor = @import("../editor.zig").Editor;
var commands: Commands = undefined; var commands: Commands = undefined;
@ -72,4 +73,24 @@ const cmds_ = struct {
}, sel); }, sel);
} }
pub const save_selection_meta: Meta = .{ .description = "Save current selection to location history" }; 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" };
}; };