From be41027d75916501062d1a06f8ab1ffe29d9dd61 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 25 Nov 2025 13:32:31 +0100 Subject: [PATCH] refactor: make Selection.from_pos infallible --- src/buffer/Selection.zig | 6 +++--- src/tui/editor.zig | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/buffer/Selection.zig b/src/buffer/Selection.zig index 3882238..cfc304f 100644 --- a/src/buffer/Selection.zig +++ b/src/buffer/Selection.zig @@ -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, }, }; } diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 94a6d73..62f7d30 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -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)) {