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,
},
};
}

View file

@ -5825,7 +5825,7 @@ pub const Editor = struct {
.push => try self.push_cursor(),
}
const root = self.buf_root() catch return;
const sel = try sel_.from_pos(root, self.metrics);
const sel = sel_.from_pos(root, self.metrics);
const primary = self.get_primary();
primary.selection = sel;
primary.cursor = sel.end;
@ -5872,7 +5872,7 @@ pub const Editor = struct {
last_end_row = end_row;
last_end_col_pos = end_col_pos;
const sel = try Selection.from_pos(.{
const sel = Selection.from_pos(.{
.begin = .{ .row = begin_row, .col = begin_col_pos },
.end = .{ .row = end_row, .col = end_col_pos },
}, root, self.metrics);
@ -5987,7 +5987,7 @@ pub const Editor = struct {
.code = try self.allocator.dupe(u8, code),
.message = try self.allocator.dupe(u8, message),
.severity = severity,
.sel = sel_.from_pos(root, self.metrics) catch return,
.sel = sel_.from_pos(root, self.metrics),
};
switch (Diagnostic.to_severity(severity)) {