Skip to content

Commit 8074a9c

Browse files
fix: anti-conceal ignore modes
## Details The `conceal` attribute of marks was previously computed once at the time of creation. However mode changes do not always cause marks to be recreated. Since the `conceal` value can depend on `mode` to support disabling anti-conceal at a per element level based on `mode` this can lead to storing incorrect values based on the current `mode`. To fix this rather than storing `conceal` as the final computed `boolean`, allow the value to a `boolean` or the `element` value associated with the mark. Then move the logic to compute the `boolean` into the main update loop, just before we either show or hide the extmark. This way the value gets recomputed based on whatever value the current `mode` is. This is fully backwards compatible, even with custom handlers, in fact it allows custom handlers to provide element strings for the `conceal` property which makes them more powerful, nice side effect.
1 parent c4ff9ac commit 8074a9c

File tree

7 files changed

+39
-35
lines changed

7 files changed

+39
-35
lines changed

doc/custom-handlers.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ Each handler must conform to the following interface:
2121
---@field root TSNode
2222

2323
---@class (exact) render.md.Mark
24-
---@field conceal boolean
24+
---@field conceal render.md.mark.Conceal
2525
---@field start_row integer
2626
---@field start_col integer
2727
---@field opts render.md.mark.Opts
2828

29+
---@alias render.md.mark.Conceal boolean|render.md.Element
30+
2931
---@class render.md.mark.Opts: vim.api.keyset.set_extmark
3032
---@field hl_mode? 'replace'|'combine'|'blend'
3133
---@field virt_text? render.md.mark.Line

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 August 21
1+
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 August 24
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/core/ui.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function Updater:display()
185185
local range = self:hidden()
186186
local extmarks = self.decorator:get()
187187
for _, extmark in ipairs(extmarks) do
188-
if extmark:get().conceal and extmark:overlaps(range) then
188+
if self:conceal(extmark, range) then
189189
extmark:hide(M.ns, self.buf)
190190
else
191191
extmark:show(M.ns, self.buf)
@@ -218,6 +218,25 @@ function Updater:hidden()
218218
end
219219
end
220220

221+
---@private
222+
---@param extmark render.md.Extmark
223+
---@param range? render.md.Range
224+
---@return boolean
225+
function Updater:conceal(extmark, range)
226+
local conceal = extmark:get().conceal
227+
if type(conceal) == 'boolean' then
228+
if not conceal then
229+
return false
230+
end
231+
else
232+
local modes = self.config.anti_conceal.ignore[conceal]
233+
if modes and env.mode.is(self.mode, modes) then
234+
return false
235+
end
236+
end
237+
return extmark:overlaps(range)
238+
end
239+
221240
---@private
222241
M.updater = Updater
223242

lua/render-markdown/debug/marks.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---@field [2]? integer
44

55
---@class render.md.debug.Mark
6-
---@field conceal boolean
6+
---@field conceal render.md.mark.Conceal
77
---@field opts render.md.mark.Opts
88
---@field row render.md.debug.Range
99
---@field col render.md.debug.Range

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.7.10'
8+
M.version = '8.7.11'
99

1010
function M.check()
1111
M.start('versions')

lua/render-markdown/lib/marks.lua

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
local compat = require('render-markdown.lib.compat')
2-
local env = require('render-markdown.lib.env')
32
local log = require('render-markdown.core.log')
43
local str = require('render-markdown.lib.str')
54

65
---@class (exact) render.md.Mark
7-
---@field conceal boolean
6+
---@field conceal render.md.mark.Conceal
87
---@field start_row integer
98
---@field start_col integer
109
---@field opts render.md.mark.Opts
1110

11+
---@alias render.md.mark.Conceal boolean|render.md.Element
12+
1213
---@class render.md.mark.Opts: vim.api.keyset.set_extmark
1314
---@field hl_mode? 'replace'|'combine'|'blend'
1415
---@field virt_text? render.md.mark.Line
@@ -23,11 +24,8 @@ local str = require('render-markdown.lib.str')
2324

2425
---@alias render.md.mark.Hl string|string[]
2526

26-
---@alias render.md.mark.Element boolean|render.md.Element
27-
2827
---@class render.md.Marks
2928
---@field private context render.md.request.Context
30-
---@field private ignore render.md.conceal.Ignore
3129
---@field private update boolean
3230
---@field private marks render.md.Mark[]
3331
local Marks = {}
@@ -39,7 +37,6 @@ Marks.__index = Marks
3937
function Marks.new(context, update)
4038
local self = setmetatable({}, Marks)
4139
self.context = context
42-
self.ignore = context.config.anti_conceal.ignore
4340
self.update = update
4441
self.marks = {}
4542
return self
@@ -50,20 +47,20 @@ function Marks:get()
5047
return self.marks
5148
end
5249

53-
---@param element render.md.mark.Element
50+
---@param conceal render.md.mark.Conceal
5451
---@param node render.md.Node
5552
---@param opts render.md.mark.Opts
5653
---@return boolean
57-
function Marks:start(element, node, opts)
58-
return self:add(element, node.start_row, node.start_col, opts)
54+
function Marks:start(conceal, node, opts)
55+
return self:add(conceal, node.start_row, node.start_col, opts)
5956
end
6057

61-
---@param element render.md.mark.Element
58+
---@param conceal render.md.mark.Conceal
6259
---@param node? render.md.Node
6360
---@param opts render.md.mark.Opts
6461
---@param offset? Range4
6562
---@return boolean
66-
function Marks:over(element, node, opts, offset)
63+
function Marks:over(conceal, node, opts, offset)
6764
if not node then
6865
return false
6966
end
@@ -72,18 +69,18 @@ function Marks:over(element, node, opts, offset)
7269
local start_col = node.start_col + offset[2]
7370
opts.end_row = node.end_row + offset[3]
7471
opts.end_col = node.end_col + offset[4]
75-
return self:add(element, start_row, start_col, opts)
72+
return self:add(conceal, start_row, start_col, opts)
7673
end
7774

78-
---@param element render.md.mark.Element
75+
---@param conceal render.md.mark.Conceal
7976
---@param start_row integer
8077
---@param start_col integer
8178
---@param opts render.md.mark.Opts
8279
---@return boolean
83-
function Marks:add(element, start_row, start_col, opts)
80+
function Marks:add(conceal, start_row, start_col, opts)
8481
---@type render.md.Mark
8582
local mark = {
86-
conceal = self:conceal(element),
83+
conceal = conceal,
8784
start_row = start_row,
8885
start_col = start_col,
8986
opts = opts,
@@ -102,21 +99,6 @@ function Marks:add(element, start_row, start_col, opts)
10299
return true
103100
end
104101

105-
---@private
106-
---@param element render.md.mark.Element
107-
---@return boolean
108-
function Marks:conceal(element)
109-
if type(element) == 'boolean' then
110-
return element
111-
end
112-
local modes = self.ignore[element]
113-
if modes == nil then
114-
return true
115-
else
116-
return not env.mode.is(self.context.mode, modes)
117-
end
118-
end
119-
120102
---@private
121103
---@param opts render.md.mark.Opts
122104
---@return boolean, string, string

scripts/update.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def update_handlers(root: Path) -> None:
158158
"render.md.Handler",
159159
"render.md.handler.Context",
160160
"render.md.Mark",
161+
"render.md.mark.Conceal",
161162
"render.md.mark.Opts",
162163
"render.md.mark.Line",
163164
"render.md.mark.Text",

0 commit comments

Comments
 (0)