feat: add Selection.from_pos function

This commit is contained in:
CJ van den Berg 2025-10-02 16:22:55 +02:00
parent 81a1c88847
commit 65eb6bc7ad
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -19,6 +19,19 @@ pub fn from_cursor(cursor: *const Cursor) Self {
return .{ .begin = cursor.*, .end = cursor.* }; 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 { pub fn line_from_cursor(cursor: Cursor, root: Buffer.Root, mtrx: Buffer.Metrics) Self {
var begin = cursor; var begin = cursor;
var end = cursor; var end = cursor;