refactor: make Selection.from_pos infallible
This commit is contained in:
parent
34af852634
commit
be41027d75
2 changed files with 6 additions and 6 deletions
|
|
@ -19,15 +19,15 @@ 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 {
|
pub fn from_pos(sel: Self, root: Buffer.Root, metrics: Buffer.Metrics) Self {
|
||||||
return .{
|
return .{
|
||||||
.begin = .{
|
.begin = .{
|
||||||
.row = sel.begin.row,
|
.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 = .{
|
.end = .{
|
||||||
.row = sel.end.row,
|
.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,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5825,7 +5825,7 @@ pub const Editor = struct {
|
||||||
.push => try self.push_cursor(),
|
.push => try self.push_cursor(),
|
||||||
}
|
}
|
||||||
const root = self.buf_root() catch return;
|
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();
|
const primary = self.get_primary();
|
||||||
primary.selection = sel;
|
primary.selection = sel;
|
||||||
primary.cursor = sel.end;
|
primary.cursor = sel.end;
|
||||||
|
|
@ -5872,7 +5872,7 @@ pub const Editor = struct {
|
||||||
last_end_row = end_row;
|
last_end_row = end_row;
|
||||||
last_end_col_pos = end_col_pos;
|
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 },
|
.begin = .{ .row = begin_row, .col = begin_col_pos },
|
||||||
.end = .{ .row = end_row, .col = end_col_pos },
|
.end = .{ .row = end_row, .col = end_col_pos },
|
||||||
}, root, self.metrics);
|
}, root, self.metrics);
|
||||||
|
|
@ -5987,7 +5987,7 @@ pub const Editor = struct {
|
||||||
.code = try self.allocator.dupe(u8, code),
|
.code = try self.allocator.dupe(u8, code),
|
||||||
.message = try self.allocator.dupe(u8, message),
|
.message = try self.allocator.dupe(u8, message),
|
||||||
.severity = severity,
|
.severity = severity,
|
||||||
.sel = sel_.from_pos(root, self.metrics) catch return,
|
.sel = sel_.from_pos(root, self.metrics),
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (Diagnostic.to_severity(severity)) {
|
switch (Diagnostic.to_severity(severity)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue