From e8606ae6bf9cd80ec4c7ed3f4a9ce0931027cb75 Mon Sep 17 00:00:00 2001 From: Immanuel Haffner Date: Fri, 20 Mar 2026 12:10:35 +0100 Subject: [PATCH] fix(tostring): resolve emoji shorthands to Unicode for correct width calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit md_str.emoji() was stripping the colons from shortcodes (e.g. :rocket: → 'rocket') but never resolving them to the actual Unicode emoji character. This caused strdisplaywidth() to return the name length (e.g. 6 for 'rocket') instead of the true on-screen width (2 for '🚀'), producing column width overestimates and misaligned table borders. Now resolve through symbols.shorthands[] — matching what the inline renderer actually displays — so width calculations are accurate. --- lua/markview/renderers/markdown/tostring.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lua/markview/renderers/markdown/tostring.lua b/lua/markview/renderers/markdown/tostring.lua index b0b55e4..b51a6fa 100644 --- a/lua/markview/renderers/markdown/tostring.lua +++ b/lua/markview/renderers/markdown/tostring.lua @@ -245,6 +245,16 @@ md_str.emoji = function (match) end local removed = string.gsub(match, "^:", ""):gsub(":$", ""); + + --- Resolve to the actual Unicode emoji so that + --- strdisplaywidth() returns the correct on-screen + --- width (typically 2) instead of the shortcode name + --- length (e.g. "rocket" = 6). + local symbols = require("markview.symbols"); + if symbols.shorthands and symbols.shorthands[removed] then + return symbols.shorthands[removed]; + end + return removed; ---|fE