aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Simmons <34775764+simmsbra@users.noreply.github.com>2023-07-20 19:56:08 -0500
committerGitHub <noreply@github.com>2023-07-21 08:56:08 +0800
commit58f94861442d182e153ba56b63b5b9845b295d2f (patch)
tree7b0dc51bd62aebe9010f4cd899e977ba322e4d1c
parent60d320dea3fe7b7d666d5a18ec8b94178c31acf4 (diff)
downloadrneovim-58f94861442d182e153ba56b63b5b9845b295d2f.tar.gz
rneovim-58f94861442d182e153ba56b63b5b9845b295d2f.tar.bz2
rneovim-58f94861442d182e153ba56b63b5b9845b295d2f.zip
fix(folds): update folds in Insert mode with fdm=indent (#24402)
Previously, when using foldmethod=indent, inserting an unindented line would inadvertently open closed folds below it. As a performance improvement, folds were only updated once, across all lines, after Insert mode was exited. Now, the performance improvement is no longer being used when foldmethod=indent, so folds are updated multiple times during Insert mode, but only across the lines that are changing, which preserves the folds (and their open/close states) instead of recreating them.
-rw-r--r--src/nvim/fold.c2
-rw-r--r--test/functional/editor/fold_spec.lua28
2 files changed, 29 insertions, 1 deletions
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 13329040e1..bdf2e26ac6 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -771,7 +771,7 @@ void clearFolding(win_T *win)
/// The changes in lines from top to bot (inclusive).
void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
{
- if (disable_fold_update || State & MODE_INSERT) {
+ if (disable_fold_update || (State & MODE_INSERT && !foldmethodIsIndent(wp))) {
return;
}
diff --git a/test/functional/editor/fold_spec.lua b/test/functional/editor/fold_spec.lua
index 0ed9d1ba80..424ce839a2 100644
--- a/test/functional/editor/fold_spec.lua
+++ b/test/functional/editor/fold_spec.lua
@@ -7,6 +7,7 @@ local expect = helpers.expect
local command = helpers.command
local funcs = helpers.funcs
local eq = helpers.eq
+local neq = helpers.neq
describe('Folds', function()
local tempfname = 'Xtest-fold.txt'
@@ -417,4 +418,31 @@ a]], '13m7')
eq(1, funcs.foldlevel(1))
eq(1, funcs.foldlevel(2))
end)
+
+ it("doesn't open folds with indent method when inserting lower foldlevel line", function()
+ insert([[
+ insert an unindented line under this line
+ keep the lines under this line folded
+ keep this line folded 1
+ keep this line folded 2
+ ]])
+ command('set foldmethod=indent shiftwidth=2 noautoindent')
+ eq(1, funcs.foldlevel(1))
+ eq(1, funcs.foldlevel(2))
+ eq(2, funcs.foldlevel(3))
+ eq(2, funcs.foldlevel(4))
+
+ feed('zo') -- open the outer fold
+ neq(-1, funcs.foldclosed(3)) -- make sure the inner fold is not open
+
+ feed('gg0oa<Esc>') -- insert unindented line
+
+ eq(1, funcs.foldlevel(1)) --| insert an unindented line under this line
+ eq(0, funcs.foldlevel(2)) --|a
+ eq(1, funcs.foldlevel(3)) --| keep the lines under this line folded
+ eq(2, funcs.foldlevel(4)) --| keep this line folded 1
+ eq(2, funcs.foldlevel(5)) --| keep this line folded 2
+
+ neq(-1, funcs.foldclosed(4)) -- make sure the inner fold is still not open
+ end)
end)