refactor: add editor focus_on_range command

This commit is contained in:
CJ van den Berg 2025-11-18 19:55:52 +01:00
parent 1d06b71102
commit 70c2673cfe
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -5711,6 +5711,37 @@ pub const Editor = struct {
}
pub const goto_line_and_column_meta: Meta = .{ .arguments = &.{ .integer, .integer } };
pub fn focus_on_range(self: *Self, ctx: Context) Result {
var sel: Selection = .{};
var pos_type: PosType = .column;
if (!try ctx.args.match(.{
tp.extract(&sel.begin.row),
tp.extract(&sel.begin.col),
tp.extract(&sel.end.row),
tp.extract(&sel.end.col),
tp.extract(&pos_type),
})) return error.InvalidFocusOnRangeArgument;
self.cancel_all_selections();
const root = self.buf_root() catch return;
if (pos_type == .byte)
sel = sel.from_pos(root, self.metrics) catch return;
const primary = self.get_primary();
try primary.cursor.move_to(
root,
sel.begin.row,
sel.begin.col,
self.metrics,
);
primary.selection = sel;
if (self.view.is_visible(&primary.cursor))
self.clamp()
else
try self.scroll_view_center(.{});
self.need_render();
}
pub const focus_on_range_meta: Meta = .{ .arguments = &.{ .integer, .integer, .integer, .integer } };
pub fn goto_byte_offset(self: *Self, ctx: Context) Result {
try self.send_editor_jump_source();
var offset: usize = 0;