diff options
author | Jaehwang Jung <tomtomjhj@gmail.com> | 2024-07-06 15:34:05 +0900 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-07-08 11:06:26 +0100 |
commit | 8474f529780ba20f9179ad1b60167ee9e53f8374 (patch) | |
tree | 70dbfc657ab4c2b88b7bf6167ffc021f11065bc3 /runtime/lua/vim/treesitter/_fold.lua | |
parent | bf92d423a9ac4bd3d30685c23a0d9a0dd772b7a7 (diff) | |
download | rneovim-8474f529780ba20f9179ad1b60167ee9e53f8374.tar.gz rneovim-8474f529780ba20f9179ad1b60167ee9e53f8374.tar.bz2 rneovim-8474f529780ba20f9179ad1b60167ee9e53f8374.zip |
fix(treesitter.foldexpr): robustness against ctrl-c
Problem:
Exiting the insert mode with ctrl-c does not trigger InsertLeave
autocmd. This may lead to nil error in treesitter foldexpr.
Solution:
Check nil. Folds still can be stale after exiting the insert mode with
ctrl-c, but it will be eventually updated correctly.
An alternative solution would be to ensure that exiting the insert mode
always triggers do_foldupdate. This can be done either by "fixing"
ctrl-c or with on_key callback that checks ctrl-c (nvim-cmp does this).
Diffstat (limited to 'runtime/lua/vim/treesitter/_fold.lua')
-rw-r--r-- | runtime/lua/vim/treesitter/_fold.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter/_fold.lua b/runtime/lua/vim/treesitter/_fold.lua index 194e09babc..27590eff5d 100644 --- a/runtime/lua/vim/treesitter/_fold.lua +++ b/runtime/lua/vim/treesitter/_fold.lua @@ -264,6 +264,15 @@ end ---@package function FoldInfo:do_foldupdate(bufnr) + -- InsertLeave is not executed when <C-C> is used for exiting the insert mode, leaving + -- do_foldupdate untouched. If another execution of foldupdate consumes foldupdate_range, the + -- InsertLeave do_foldupdate gets nil foldupdate_range. In that case, skip the update. This is + -- correct because the update that consumed the range must have incorporated the range that + -- InsertLeave meant to update. + if not self.foldupdate_range then + return + end + local srow, erow = self.foldupdate_range[1], self.foldupdate_range[2] self.foldupdate_range = nil for _, win in ipairs(vim.fn.win_findbuf(bufnr)) do |