Skip to content

Commit f365cef

Browse files
fix: account for link icons added to headings when computing width
# Details Issue: #124 Calculation for heading width did not take into account any inlined link icons added. This would cause text to be hidden when using the block width. To fix this use similar logic to the table padding caclulation and add the width of any inlined icons.
1 parent 57b96df commit f365cef

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lua/render-markdown/handler/markdown.lua

+10-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function Handler:heading(info)
103103
local width = heading.left_pad + icon_width + heading.right_pad
104104
local content = info:sibling('inline')
105105
if content ~= nil then
106-
width = width + str.width(content.text) - content:concealed()
106+
width = width + str.width(content.text) + self:added_width(content) - content:concealed()
107107
end
108108
self:add(true, info.start_row, 0, {
109109
priority = 0,
@@ -593,11 +593,18 @@ end
593593
---@param info render.md.NodeInfo
594594
---@return integer
595595
function Handler:table_visual_offset(info)
596-
local result = info:concealed()
596+
return info:concealed() - self:added_width(info)
597+
end
598+
599+
---@private
600+
---@param info render.md.NodeInfo
601+
---@return integer
602+
function Handler:added_width(info)
603+
local result = 0
597604
local icon_ranges = context.get(self.buf):get_links(info.start_row)
598605
for _, icon_range in ipairs(icon_ranges) do
599606
if info.start_col < icon_range[2] and info.end_col > icon_range[1] then
600-
result = result - str.width(icon_range[3])
607+
result = result + str.width(icon_range[3])
601608
end
602609
end
603610
return result

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.0.6'
8+
M.version = '6.0.7'
99

1010
function M.check()
1111
vim.health.start('render-markdown.nvim [version]')

0 commit comments

Comments
 (0)