kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.16k stars 37 forks source link

Only visible folds are closed #192

Closed Rizhiy closed 5 months ago

Rizhiy commented 5 months ago

Neovim version (nvim -v | head -n1)

NVIM v0.9.4

Operating system/version

Ubuntu 22.04

How to reproduce the issue

Add auto-fold on open script, but only fold to first level:

local function applyFoldsAndThenCloseAllFolds(bufnr, providerName)
    require("async")(function()
        bufnr = bufnr or vim.api.nvim_get_current_buf()
        -- make sure buffer is attached
        require("ufo").attach(bufnr)
        local ranges = require("ufo").getFolds(bufnr, providerName)
        local ok = require("ufo").applyFolds(bufnr, ranges)
        if ok then require("ufo").closeFoldsWith(1) end
    end)
end

vim.api.nvim_create_autocmd("BufRead", {
    pattern = "*",
    callback = function(e) applyFoldsAndThenCloseAllFolds(e.buf, "treesitter") end,
})

Expected behavior

All folds upto first level are closed when file is opened.

Actual behavior

Only those folds that are visible are closed, if I scroll down the code is not folded.