From 9dc85bf80208463a337ab56cad6dc94c1960662b Mon Sep 17 00:00:00 2001 From: Lukas Reineke Date: Sat, 2 Dec 2023 11:02:44 +0900 Subject: [PATCH] fix: foldclosed for inactive buffers --- lua/ibl/init.lua | 2 +- lua/ibl/utils.lua | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/ibl/init.lua b/lua/ibl/init.lua index a4b47f89..ccdefc1e 100644 --- a/lua/ibl/init.lua +++ b/lua/ibl/init.lua @@ -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) diff --git a/lua/ibl/utils.lua b/lua/ibl/utils.lua index 379d4a41..ab0796fe 100644 --- a/lua/ibl/utils.lua +++ b/lua/ibl/utils.lua @@ -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 @@ -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)