Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically folds after deleting newlines between folds #94

Closed
ipsod opened this issue Nov 12, 2022 · 6 comments
Closed

automatically folds after deleting newlines between folds #94

ipsod opened this issue Nov 12, 2022 · 6 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@ipsod
Copy link

ipsod commented Nov 12, 2022

Neovim version (nvim -v | head -n1)

NVIM v0.9.0-dev

Operating system/version

linux mint 21

How to reproduce the issue

create text file with multiple levels of folds:

test
    row
        sub
        sub
    row
        sub
        sub

fold to hide sub, but show row (set foldlevel=1, I think)

insert or delete a blank newline between the two row folds. Both inserting and deleting cause it.

editor will now automatically (and undesirably) fold all the way, and hide rows

Expected behavior

fold level should not change because of modification of text

Actual behavior

The text you're editing gets folded because you edited the text. Especially troublesome if it folds, then you end up deleting N folded lines instead of the single unfolded line you meant to.

@ipsod ipsod added the bug Something isn't working label Nov 12, 2022
@kevinhwang91
Copy link
Owner

Using a provider of ufo, must set a large value for foldlevel, this is the limitation of foldmethod=manual. A small value may close fold automatically if the fold ranges updated.

#7
#57
#89

@kevinhwang91 kevinhwang91 added the duplicate This issue or pull request already exists label Nov 12, 2022
@ipsod
Copy link
Author

ipsod commented Nov 12, 2022

Ah, I see. Sorry about that.

Is the config here supposed to restore normal functionality to zm, zM, zr, and zR? https://github.com/kevinhwang91/nvim-ufo#customize-configuration

I copied it directly, and zm and zr seem to have the same behavior as zM and zR.

@kevinhwang91
Copy link
Owner

  1. number + zm.
  2. zr is the same as zM if the kind is excluded in close_fold_kinds.

@ipsod
Copy link
Author

ipsod commented Nov 12, 2022

Is there a way to just increment/deincrement mock-indent-level, to simulate standard behavior?

@kevinhwang91
Copy link
Owner

No, foldlevel should keep a large value. Must maintain your_foldlevel by yourself. Need to write a script.

vim.api.nvim_create_autocmd({'WinNew', 'VimEnter'}, {
    pattern = '*',
    callback = function()
        vim.w.my_foldlevel = 20
    end
})

vim.keymap.set('n', 'zr', function()
    vim.w.my_foldlevel = vim.w.my_foldlevel - 1
    require('ufo').closeFoldsWith(vim.w.my_foldlevel)
end)

vim.keymap.set('n', 'zm', function()
    vim.w.my_foldlevel = vim.w.my_foldlevel + 1
    require('ufo').closeFoldsWith(vim.w.my_foldlevel)
end)

@ipsod
Copy link
Author

ipsod commented Nov 12, 2022

This seems to be working well. Thanks for the help!

    vim.api.nvim_create_autocmd({'WinNew', 'VimEnter'}, {
        pattern = '*',
        callback = function()
            vim.w.my_foldlevel = 1
        end
    })

    vim.keymap.set('n', 'zM', function()
        vim.w.my_foldlevel = 0
        require('ufo').closeFoldsWith(vim.w.my_foldlevel)
    end)

    vim.keymap.set('n', 'zR', function()
        vim.w.my_foldlevel = 5
        require('ufo').closeFoldsWith(vim.w.my_foldlevel)
    end)

    vim.keymap.set('n', 'zr', function()
        vim.w.my_foldlevel = vim.w.my_foldlevel + 1
        require('ufo').closeFoldsWith(vim.w.my_foldlevel)
    end)

    vim.keymap.set('n', 'zm', function()
        vim.w.my_foldlevel = math.max(vim.w.my_foldlevel - 1, 0)

        require('ufo').closeFoldsWith(vim.w.my_foldlevel)
    end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants