Skip to content

Commit 19e4bea

Browse files
committed
fix(concealer): don't overflow folds into other, non-norg files
1 parent 1af103b commit 19e4bea

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

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

+28-22
Original file line numberDiff line numberDiff line change
@@ -1271,8 +1271,6 @@ local function update_cursor(event)
12711271
end
12721272

12731273
local function handle_init_event(event)
1274-
-- TODO: make sure only init once
1275-
12761274
assert(vim.api.nvim_win_is_valid(event.window))
12771275
update_cursor(event)
12781276

@@ -1315,30 +1313,38 @@ local function handle_init_event(event)
13151313
language_tree:register_cbs({ on_changedtree = on_changedtree_callback })
13161314
mark_all_lines_changed(event.buffer)
13171315

1318-
if module.config.public.folds and vim.api.nvim_win_is_valid(event.window) then
1319-
local wo = vim.wo[event.window]
1320-
wo.foldmethod = "expr"
1321-
wo.foldexpr = vim.treesitter.foldexpr and "v:lua.vim.treesitter.foldexpr()" or "nvim_treesitter#foldexpr()"
1322-
wo.foldtext = ""
1323-
1324-
local init_open_folds = module.config.public.init_open_folds
1325-
local function open_folds()
1326-
vim.cmd("normal! zR")
1327-
end
1328-
1329-
if init_open_folds == "always" then
1330-
open_folds()
1331-
elseif init_open_folds == "never" then -- luacheck:ignore 542
1332-
-- do nothing
1333-
else
1334-
if init_open_folds ~= "auto" then
1335-
log.warn('"init_open_folds" must be "auto", "always", or "never"')
1316+
if
1317+
module.config.public.folds
1318+
and vim.api.nvim_win_is_valid(event.window)
1319+
and vim.api.nvim_buf_is_valid(event.buffer)
1320+
then
1321+
vim.api.nvim_buf_call(event.buffer, function()
1322+
-- NOTE(vhyrro): `vim.wo` only supports `wo[winid][0]`,
1323+
-- hence the `buf_call` here.
1324+
local wo = vim.wo[event.window][0]
1325+
wo.foldmethod = "expr"
1326+
wo.foldexpr = vim.treesitter.foldexpr and "v:lua.vim.treesitter.foldexpr()" or "nvim_treesitter#foldexpr()"
1327+
wo.foldtext = ""
1328+
1329+
local init_open_folds = module.config.public.init_open_folds
1330+
local function open_folds()
1331+
vim.cmd("normal! zR")
13361332
end
13371333

1338-
if wo.foldlevel == 0 then
1334+
if init_open_folds == "always" then
13391335
open_folds()
1336+
elseif init_open_folds == "never" then -- luacheck:ignore 542
1337+
-- do nothing
1338+
else
1339+
if init_open_folds ~= "auto" then
1340+
log.warn('"init_open_folds" must be "auto", "always", or "never"')
1341+
end
1342+
1343+
if wo.foldlevel == 0 then
1344+
open_folds()
1345+
end
13401346
end
1341-
end
1347+
end)
13421348
end
13431349
end
13441350

0 commit comments

Comments
 (0)