From e9a7d681f25a7e8355987e046d450036a7081c43 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 11 Oct 2024 21:05:35 +0200 Subject: [PATCH] fix: add missing pos_to_width calls in add_diagnostic This will fix the positioning of diagnostics in lines that have glyphs with widths != 1 like tabs or emojis. --- src/tui/editor.zig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 90d5f60..a83e6b5 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -3676,10 +3676,22 @@ pub const Editor = struct { code: []const u8, message: []const u8, severity: i32, - sel: Selection, + sel_: Selection, ) Result { if (!std.mem.eql(u8, file_path, self.file_path orelse return)) return; + const root = self.buf_root() catch return; + const sel: Selection = .{ + .begin = .{ + .row = sel_.begin.row, + .col = root.pos_to_width(sel_.begin.row, sel_.begin.col, self.metrics) catch return, + }, + .end = .{ + .row = sel_.end.row, + .col = root.pos_to_width(sel_.end.row, sel_.end.col, self.metrics) catch return, + }, + }; + (try self.diagnostics.addOne()).* = .{ .source = try self.diagnostics.allocator.dupe(u8, source), .code = try self.diagnostics.allocator.dupe(u8, code),