Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: foldclosed for inactive buffers #781

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading