From 77ee2f413cc290409c9e5cbb19fb0e29cd25041a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Jul 2024 14:36:49 -0700 Subject: [PATCH] terminal: hasText no longer special cases kitty placeholders --- src/font/shaper/run.zig | 20 +++++++++++++++++++- src/terminal/page.zig | 15 ++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/font/shaper/run.zig b/src/font/shaper/run.zig index ef55ba981..8d53c601b 100644 --- a/src/font/shaper/run.zig +++ b/src/font/shaper/run.zig @@ -228,6 +228,12 @@ pub const RunIterator = struct { continue; } + // If we're a Kitty unicode placeholder then we add a blank. + if (cell.codepoint() == terminal.kitty.graphics.unicode.placeholder) { + try self.addCodepoint(&hasher, ' ', @intCast(cluster)); + continue; + } + // Add all the codepoints for our grapheme try self.addCodepoint( &hasher, @@ -284,8 +290,20 @@ pub const RunIterator = struct { style: font.Style, presentation: ?font.Presentation, ) !?font.Collection.Index { + if (cell.isEmpty() or + cell.codepoint() == 0 or + cell.codepoint() == terminal.kitty.graphics.unicode.placeholder) + { + return try self.grid.getIndex( + alloc, + ' ', + style, + presentation, + ); + } + // Get the font index for the primary codepoint. - const primary_cp: u32 = if (cell.isEmpty() or cell.codepoint() == 0) ' ' else cell.codepoint(); + const primary_cp: u32 = cell.codepoint(); const primary = try self.grid.getIndex( alloc, primary_cp, diff --git a/src/terminal/page.zig b/src/terminal/page.zig index c270a0e0d..b396493fe 100644 --- a/src/terminal/page.zig +++ b/src/terminal/page.zig @@ -1705,8 +1705,7 @@ pub const Cell = packed struct(u64) { return switch (self.content_tag) { .codepoint, .codepoint_grapheme, - => self.content.codepoint != 0 and - self.content.codepoint != kitty.graphics.unicode.placeholder, + => self.content.codepoint != 0, .bg_color_palette, .bg_color_rgb, @@ -1738,8 +1737,7 @@ pub const Cell = packed struct(u64) { return self.style_id != style.default_id; } - /// Returns true if the cell has no text or styling. This also returns - /// true if the cell represents a Kitty graphics unicode placeholder. + /// Returns true if the cell has no text or styling. pub fn isEmpty(self: Cell) bool { return switch (self.content_tag) { // Textual cells are empty if they have no text and are narrow. @@ -2671,12 +2669,3 @@ test "Page verifyIntegrity zero cols" { page.verifyIntegrity(testing.allocator), ); } - -test "Cell isEmpty for kitty placeholder" { - var c: Cell = .{ - .content_tag = .codepoint_grapheme, - .content = .{ .codepoint = kitty.graphics.unicode.placeholder }, - }; - try testing.expectEqual(@as(u21, kitty.graphics.unicode.placeholder), c.codepoint()); - try testing.expect(c.isEmpty()); -}