refactor: make Selection.from_pos infallible

This commit is contained in:
CJ van den Berg 2025-11-25 13:32:31 +01:00
parent 34af852634
commit be41027d75
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 6 additions and 6 deletions

View file

@ -19,15 +19,15 @@ 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 {
pub fn from_pos(sel: Self, root: Buffer.Root, metrics: Buffer.Metrics) Self {
return .{
.begin = .{
.row = sel.begin.row,
.col = try root.pos_to_width(sel.begin.row, sel.begin.col, metrics),
.col = root.pos_to_width(sel.begin.row, sel.begin.col, metrics) catch root.line_width(sel.begin.row, metrics) catch 0,
},
.end = .{
.row = sel.end.row,
.col = try root.pos_to_width(sel.end.row, sel.end.col, metrics),
.col = root.pos_to_width(sel.end.row, sel.end.col, metrics) catch root.line_width(sel.end.row, metrics) catch 0,
},
};
}