kevinhwang91 / nvim-ufo

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

Line under fold is eaten up with a keybinding #23

Closed lmburns closed 2 years ago

lmburns commented 2 years ago

Neovim version (nvim -v | head -n1)

NVIM v0.8.0-dev+457-g6d52a29c3

Operating system/version

Linux archbox 5.18.5-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 16 Jun 2022 20:40:45 +0000 x86_64 GNU/Linux

How to reproduce the issue

Whenever using UFO, the normal fold keybindings work just fine; however, a keybinding like this does not:

-- This is meant to toggle a fold (i.e., open if it is closed, close if it is open)
map("n", "z;", "@=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>", {silent = true})

Something else that is similar that also doesn't work is this:

-- File: lua/plugs/fold.lua
M.open_fold = function()
    if fn.foldclosed(".") == -1 then
        ex.foldclose()
    else
        while fn.foldclosed(".") ~= -1 do
            ex.foldopen()
        end
    end
end

map("n", "z,", ":lua require('plugs.fold').open_fold()<CR>")

Go to any fold and press z;

Expected behavior

The expected behavior is for the keybinding z; to open the fold after it closes it.

Actual behavior

What ends up happening is that the line under the fold gets 'eaten' up and brought into the fold that is under the cursor. Here is a video showing what it does. I press zc, zo, z;, z;, z; (the keybinding above). The z; also seems to turn every single line into a fold.

cut

I'm unsure if this is specific to my configuration or not. I have found that the issue is with this autocmd:

au CmdlineLeave * lua require('ufo.event').emit('CmdlineLeave')

I also have anyfold installed. When the fold starts to get 'eaten', if I run AnyFoldActivate, it resets the folds and prevents the issue as mentioned above. Then the keybinding z; will work just fine.

A way to solve this is to add a return statement after line 125 in ufo/fold.lua.

https://github.com/kevinhwang91/nvim-ufo/blob/c412ff87165eb8712e2810799dfa90b728c40028/lua/ufo/fold.lua#L125

I'm doubt this is the correct way to solve this issue, but it does seem to work for my problem and I haven't ran into anything else yet.

kevinhwang91 commented 2 years ago

can reproduce. why not za?