Skip to content

Commit

Permalink
fix: foldclosed for inactive buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-reineke committed Dec 2, 2023
1 parent 29be091 commit 9dc85bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/ibl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ M.refresh = function(bufnr)
end

local whitespace = utils.get_whitespace(line)
local foldclosed = vim.fn.foldclosed(row)
local foldclosed = utils.get_foldclosed(bufnr, row)
if is_current_buffer and foldclosed == row then
local foldtext = vim.fn.foldtextresult(row)
local foldtext_whitespace = utils.get_whitespace(foldtext)
Expand Down
19 changes: 19 additions & 0 deletions lua/ibl/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ M.has_end = function(line)
end

---@param bufnr number
---@return number, number, number, number
M.get_offset = function(bufnr)
local win
local win_view
Expand Down Expand Up @@ -198,6 +199,24 @@ M.get_offset = function(bufnr)
return win_view.leftcol or 0, win_view.topline or 0, win_end, win_height
end

---@param bufnr number
---@param row number
---@return number
M.get_foldclosed = function(bufnr, row)
if bufnr == vim.api.nvim_get_current_buf() then
return vim.fn.foldclosed(row) or -1
else
local win = M.get_win(bufnr)
if not win then
return -1
end
return vim.api.nvim_win_call(win, function()
---@diagnostic disable-next-line: redundant-return-value
return vim.fn.foldclosed(row) or -1
end)
end
end

---@param bufnr number
---@param config ibl.config
M.is_buffer_active = function(bufnr, config)
Expand Down

0 comments on commit 9dc85bf

Please sign in to comment.