Open kevinhwang91 opened 2 years ago
local function hateRepeatFold(char)
local function setScrollOff(val)
local view = vim.fn.winsaveview()
vim.wo.so = val
vim.fn.winrestview(view)
end
local event = require('ufo.lib.event')
event:emit('setOpenFoldHl')
vim.keymap.set('n', 'h', function()
local shouldClose = vim.fn.foldlevel('.') ~= 0
if shouldClose then
event:emit('setOpenFoldHl', false)
setScrollOff(10)
end
return shouldClose and 'zc' or 'h'
end, {buffer = 0, expr = true})
vim.keymap.set('n', 'l', function()
local shouldOpen = vim.fn.foldclosed('.') ~= -1
if shouldOpen then
event:emit('setOpenFoldHl', false)
setScrollOff(10)
end
return shouldOpen and 'zo' or 'l'
end, {buffer = 0, expr = true})
vim.api.nvim_create_autocmd('CursorMoved', {
group = vim.api.nvim_create_augroup('HateRepeatFoldAug', {}),
buffer = 0,
once = true,
callback = function()
pcall(vim.keymap.del, 'n', 'h', {buffer = 0})
pcall(vim.keymap.del, 'n', 'l', {buffer = 0})
setScrollOff(0)
event:emit('setOpenFoldHl')
end
})
return 'mzz' .. char
end
for _, c in ipairs({'c', 'o', 'a', 'C', 'O', 'A', 'v'}) do
vim.keymap.set('n', 'z' .. c, function() return hateRepeatFold(c) end, {expr = true})
end
I'm using this script to improve native fold actions. Any feedbacks are welcome. If this is not bad, only export an API to enable/disable open fold highlighting on-the-fly.
n zO * <Lua 406: ~/.config/nvim/lua/custom/configs/ufo.lua:74>
Last set from Lua
https://github.com/kevinhwang91/nvim-ufo/assets/37143421/69d2703a-0c4a-4330-9104-5648820c6659
I think I have a pretty reasonable workflow: hide everything with zM, then only open what I need with zo or zO, but when editing it automatically closes the opened fold. This is really annoying, and it not only happens with the default keymaps, but also with the snippet above. I really thought it would fix it, but it doesn't. Do you know why it does that? But works fine after zR?
n zO * <Lua 406: ~/.config/nvim/lua/custom/configs/ufo.lua:74> Last set from Lua
auto-close-folds.mp4 I think I have a pretty reasonable workflow: hide everything with zM, then only open what I need with zo or zO, but when editing it automatically closes the opened fold. This is really annoying, and it not only happens with the default keymaps, but also with the snippet above. I really thought it would fix it, but it doesn't. Do you know why it does that? But works fine after zR?
my setup
Not related to this issue, please follow the setup in README and check out your foldlevel
.
I did follow and it looks like nothing helps. I posted an issue: https://github.com/kevinhwang91/nvim-ufo/issues/206.
Feature description
Sometimes it's too unexpected while typing
zC
andzO
.Describe the solution you'd like
Use a selector with a preview based on foldlevel to show the result.
Additional context
No response