Skip to content

Commit

Permalink
feat: support empty foldtext in nvim 0.10
Browse files Browse the repository at this point in the history
Neovim 0.10 changed the behavior for when `'foldtext'` is empty.
It now displays the line normally with highlighting.

`vim.fn.foldtextresult` does however not reflect this change and returns
the previous foldtext, like `+--  4 lines folded`. This breaks the
current implementation which checks if indentation lines can be
displayed over the foldtext.

So until (if ever) this gets fixed, we need to do a custom check.

fix #901
  • Loading branch information
lukas-reineke committed Jun 26, 2024
1 parent 4036c8a commit 1696ea4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lua/ibl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ M.refresh = function(bufnr)
indent_opts.vartabstop = ""
end

local has_empty_foldtext = utils.has_empty_foldtext(bufnr)

local indent_state
local next_whitespace_tbl = {}
local empty_line_counter = 0
Expand Down Expand Up @@ -316,7 +318,7 @@ M.refresh = function(bufnr)

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

---@param bufnr number
---@return boolean
M.has_empty_foldtext = function(bufnr)
if vim.fn.has "nvim-0.10" == 0 then
return false
end
local win = M.get_win(bufnr)
if not win then
return false
end
return vim.api.nvim_get_option_value("foldtext", { win = win }) == ""
end

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

0 comments on commit 1696ea4

Please sign in to comment.