From 62b8493b93dd9e32321cde9d82a61e36d15f4c38 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 14 Aug 2025 16:30:46 +0200 Subject: [PATCH] fix: correct match offsets when show_fileicons is off --- src/tui/mode/overlay/file_type_palette.zig | 4 ++-- src/tui/tui.zig | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/tui/mode/overlay/file_type_palette.zig b/src/tui/mode/overlay/file_type_palette.zig index 9660df1..1815f00 100644 --- a/src/tui/mode/overlay/file_type_palette.zig +++ b/src/tui/mode/overlay/file_type_palette.zig @@ -95,7 +95,7 @@ pub fn Variant(comptime command: []const u8, comptime label_: []const u8, allow_ if (!(cbor.matchString(&iter, &icon_) catch false)) @panic("invalid file_type icon"); if (!(cbor.matchInt(u24, &iter, &color) catch false)) @panic("invalid file_type color"); - tui.render_file_icon(&button.plane, icon_, color); + const icon_width = tui.render_file_icon(&button.plane, icon_, color); button.plane.set_style(style_label); _ = button.plane.print("{s} ", .{description_}) catch {}; @@ -110,7 +110,7 @@ pub fn Variant(comptime command: []const u8, comptime label_: []const u8, allow_ var len = cbor.decodeArrayHeader(&iter) catch return false; while (len > 0) : (len -= 1) { if (cbor.matchValue(&iter, cbor.extract(&index)) catch break) { - tui.render_match_cell(&button.plane, 0, index + 4, theme) catch break; + tui.render_match_cell(&button.plane, 0, index + 2 + icon_width, theme) catch break; } else break; } return false; diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 15d8c58..c84880c 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -1463,8 +1463,8 @@ pub fn get_buffer_state_indicator(buffer: *const @import("Buffer")) []const u8 { return if (buffer.is_dirty()) dirty_indicator else if (buffer.is_hidden()) hidden_indicator else ""; } -pub fn render_file_icon(self: *renderer.Plane, icon: []const u8, color: u24) void { - if (!config().show_fileicons) return; +pub fn render_file_icon(self: *renderer.Plane, icon: []const u8, color: u24) usize { + if (!config().show_fileicons) return 0; var cell = self.cell_init(); _ = self.at_cursor_cell(&cell) catch return; if (!(color == 0xFFFFFF or color == 0x000000 or color == 0x000001)) { @@ -1474,6 +1474,7 @@ pub fn render_file_icon(self: *renderer.Plane, icon: []const u8, color: u24) voi _ = self.putc(&cell) catch {}; self.cursor_move_rel(0, 1) catch {}; _ = self.print(" ", .{}) catch {}; + return 3; } pub fn render_match_cell(self: *renderer.Plane, y: usize, x: usize, theme_: *const Widget.Theme) !void { @@ -1513,7 +1514,7 @@ pub fn render_file_item_cbor(self: *renderer.Plane, file_item_cbor: []const u8, if (!(cbor.matchString(&iter, &icon) catch false)) @panic("invalid buffer file type icon"); if (!(cbor.matchInt(u24, &iter, &color) catch false)) @panic("invalid buffer file type color"); - render_file_icon(self, icon, color); + const icon_width = render_file_icon(self, icon, color); self.set_style(style_label); _ = self.print("{s} ", .{file_path_}) catch {}; @@ -1528,7 +1529,7 @@ pub fn render_file_item_cbor(self: *renderer.Plane, file_item_cbor: []const u8, var len = cbor.decodeArrayHeader(&iter) catch return false; while (len > 0) : (len -= 1) { if (cbor.matchValue(&iter, cbor.extract(&index)) catch break) { - render_match_cell(self, 0, index + 5, theme_) catch break; + render_match_cell(self, 0, index + 2 + icon_width, theme_) catch break; } else break; } return false;