Skip to content

Commit dd0f29b

Browse files
committed
fix(concealer): errors when leaving Neovim right after BufEnter (#292)
1 parent 5434c2e commit dd0f29b

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

lua/neorg/modules/core/norg/concealer/module.lua

+30-19
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,12 @@ module.public = {
397397
-- @Param end_column (number) - the end column of the conceal
398398
-- @Param whole_line (boolean) - if true will highlight the whole line (like in diffs)
399399
-- @Param mode (string: "replace"/"combine"/"blend") - the highlight mode for the extmark
400-
_set_extmark = function(buf, text, highlight, ns, line_number, end_line, start_column, end_column, whole_line, mode)
400+
-- @Param pos (string: "overlay"/"eol"/"right_align") - the position to place the extmark in (defaults to "overlay")
401+
_set_extmark = function(buf, text, highlight, ns, line_number, end_line, start_column, end_column, whole_line, mode, pos)
402+
if not vim.api.nvim_buf_is_loaded(buf) then
403+
return
404+
end
405+
401406
-- If the text type is a string then convert it into something that Neovim's extmark API can understand
402407
if type(text) == "string" then
403408
text = { { text, highlight } }
@@ -408,8 +413,8 @@ module.public = {
408413
end_col = end_column,
409414
hl_group = highlight,
410415
end_line = end_line,
411-
virt_text = text or nil,
412-
virt_text_pos = "overlay",
416+
virt_text = text,
417+
virt_text_pos = pos or "overlay",
413418
hl_mode = mode,
414419
hl_eol = whole_line,
415420
})
@@ -469,18 +474,21 @@ module.public = {
469474
local todo_item_counts = module.public.completion_levels.get_todo_item_counts(parent)
470475

471476
if todo_item_counts.total ~= 0 then
472-
vim.api.nvim_buf_set_extmark(
477+
module.public._set_extmark(
473478
buf,
479+
module.public.completion_levels.convert_query_syntax_to_extmark_syntax(
480+
query.text,
481+
todo_item_counts
482+
),
483+
query.highlight,
474484
module.private.completion_level_namespace,
475485
parent_range.row_start,
486+
nil,
476487
parent_range.column_start,
477-
{
478-
virt_text = module.public.completion_levels.convert_query_syntax_to_extmark_syntax(
479-
query.text,
480-
todo_item_counts
481-
),
482-
hl_group = query.highlight,
483-
}
488+
nil,
489+
nil,
490+
nil,
491+
"eol"
484492
)
485493
end
486494
end)
@@ -533,18 +541,21 @@ module.public = {
533541
local todo_item_counts = module.public.completion_levels.get_todo_item_counts(node)
534542

535543
if todo_item_counts.total ~= 0 then
536-
vim.api.nvim_buf_set_extmark(
544+
module.public._set_extmark(
537545
buf,
546+
module.public.completion_levels.convert_query_syntax_to_extmark_syntax(
547+
data.text,
548+
todo_item_counts
549+
),
550+
data.highlight,
538551
module.private.completion_level_namespace,
539552
node_range.row_start,
553+
nil,
540554
node_range.column_start,
541-
{
542-
virt_text = module.public.completion_levels.convert_query_syntax_to_extmark_syntax(
543-
data.text,
544-
todo_item_counts
545-
),
546-
hl_group = data.highlight,
547-
}
555+
nil,
556+
nil,
557+
nil,
558+
"eol"
548559
)
549560
end
550561
end)

lua/neorg/modules/core/norg/esupports/metagen/module.lua

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ module.on_event = function(event)
140140
if
141141
event.type == "core.autocommands.events.bufenter"
142142
and event.content.norg
143+
and vim.api.nvim_buf_is_loaded(event.buffer)
143144
and module.config.public.type == "auto"
144145
and vim.api.nvim_buf_get_option(event.buffer, "modifiable")
145146
and not module.private.buffers[event.buffer]

0 commit comments

Comments
 (0)