From 65eb6bc7ad0cf5eaf6d568a8248aba76c65191fc Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 2 Oct 2025 16:22:55 +0200 Subject: [PATCH] feat: add Selection.from_pos function --- src/buffer/Selection.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/buffer/Selection.zig b/src/buffer/Selection.zig index b87064b..5ea9df5 100644 --- a/src/buffer/Selection.zig +++ b/src/buffer/Selection.zig @@ -19,6 +19,19 @@ pub fn from_cursor(cursor: *const Cursor) Self { return .{ .begin = cursor.*, .end = cursor.* }; } +pub fn from_pos(sel: Self, root: Buffer.Root, metrics: Buffer.Metrics) error{NotFound}!Self { + return .{ + .begin = .{ + .row = sel.begin.row, + .col = try root.pos_to_width(sel.begin.row, sel.begin.col, metrics), + }, + .end = .{ + .row = sel.end.row, + .col = try root.pos_to_width(sel.end.row, sel.end.col, metrics), + }, + }; +} + pub fn line_from_cursor(cursor: Cursor, root: Buffer.Root, mtrx: Buffer.Metrics) Self { var begin = cursor; var end = cursor;