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

Setting ufo's highlight groups to None doesn't remove folding hightlights #227

Closed efrsw closed 2 weeks ago

efrsw commented 2 weeks ago

Neovim version (nvim -v | head -n1)

NVIM v0.10.0 Release

Operating system/version

Windows 10

How to reproduce the issue

I am not sure if this is a bug or I am doing something incorrectly.

I want to remove highlighting of folded regions with the following configuration:

return {
    "kevinhwang91/nvim-ufo",
    dependencies = { "kevinhwang91/promise-async" },
    keys = {
        {
            "zR",
            require("ufo").openAllFolds,
            mode = { "n" },
            desc = "Open all folds",
        },
        {
            "zM",
            require("ufo").closeAllFolds,
            mode = { "n" },
            desc = "Close all folds",
        },
        {
            "zr",
            require("ufo").openFoldsExceptKinds,
            mode = { "n" },
        },
        {
            "zm",
            require("ufo").closeFoldsWith,
            mode = { "n" },
        },
        {
            "K",
            function()
                local winid = require("ufo").peekFoldedLinesUnderCursor()
                if not winid then
                    vim.lsp.buf.hover()
                end
            end,
            mode = { "n" },
        },
    },
    config = function()
        vim.o.foldcolumn = "1" -- '0' is not bad
        vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
        vim.o.foldlevelstart = 99
        vim.o.foldenable = true

        -- show amount of folded lines instead of default thing
        local handler = function(virtText, lnum, endLnum, width, truncate)
            local newVirtText = {}
            local suffix = (" 󰁂 %d "):format(endLnum - lnum)
            local sufWidth = vim.fn.strdisplaywidth(suffix)
            local targetWidth = width - sufWidth
            local curWidth = 0
            for _, chunk in ipairs(virtText) do
                local chunkText = chunk[1]
                local chunkWidth = vim.fn.strdisplaywidth(chunkText)
                if targetWidth > curWidth + chunkWidth then
                    table.insert(newVirtText, chunk)
                else
                    chunkText = truncate(chunkText, targetWidth - curWidth)
                    local hlGroup = chunk[2]
                    table.insert(newVirtText, { chunkText, hlGroup })
                    chunkWidth = vim.fn.strdisplaywidth(chunkText)
                    -- str width returned from truncate() may less than 2nd argument, need padding
                    if curWidth + chunkWidth < targetWidth then
                        suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
                    end
                    break
                end
                curWidth = curWidth + chunkWidth
            end
            table.insert(newVirtText, { suffix, "MoreMsg" })
            return newVirtText
        end

        vim.cmd([[
        highlight UfoFoldedFg ctermfg=NONE ctermbg=NONE guifg=NONE guibg=NONE
        highlight UfoFoldedBg ctermfg=NONE ctermbg=NONE guifg=NONE guibg=NONE
        ]])

        require("ufo").setup({
            provider_selector = function(bufnr, filetype, buftype)
                return { "treesitter", "indent" }
            end,
            fold_virt_text_handler = handler,
        })
    end,
}

However, it isn't removed as expected.

Expected behavior

The highlights are removed (lines 2 and 3 should be the same color):

image

Actual behavior

Highlights aren't removed :(

kevinhwang91 commented 2 weeks ago

hi Folded guibg=NONE

efrsw commented 2 weeks ago

Thank you!