Skip to content

Commit 5b5cc1f

Browse files
Optimize markup highlighter to not highlight folded lines
1 parent 2ea0d6b commit 5b5cc1f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lua/orgmode/colors/markup_highlighter.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,18 @@ local function get_matches(bufnr, first_line, last_line)
236236
end
237237

238238
local function apply(namespace, bufnr, _, first_line, last_line, _)
239-
local ranges, link_ranges = get_matches(bufnr, first_line, last_line)
239+
local visible_lines = {}
240+
-- Add some offset to make sure everything is covered
241+
local start_line = math.max(0, first_line - 5)
242+
for i = start_line, last_line do
243+
if vim.fn.foldclosed(i + 1) == -1 then
244+
table.insert(visible_lines, i)
245+
end
246+
end
247+
if #visible_lines == 0 then
248+
return
249+
end
250+
local ranges, link_ranges = get_matches(bufnr, visible_lines[1], visible_lines[#visible_lines])
240251
local hide_markers = config.org_hide_emphasis_markers
241252

242253
for _, range in ipairs(ranges) do

0 commit comments

Comments
 (0)