Skip to content

Commit ca298b1

Browse files
1grzyb1AlexPl292
authored andcommitted
VIM-566 Skip fold-level application during initialization
1 parent 8651b8f commit ca298b1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/java/com/maddyhome/idea/vim/group/OptionGroup.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,22 @@ private class FoldLevelOptionMapper : LocalOptionValueOverride<VimInt> {
13571357
val maxDepth = editor.getMaxFoldDepth()
13581358
val coercedLevel = newValue.value.value.coerceIn(0, maxDepth + 1)
13591359

1360-
editor.applyFoldLevel(coercedLevel)
1360+
// When a new window opens, setLocalValue is called twice: first from copyLocalToWindowLocalValues,
1361+
// then from initialiseLocalToWindowOptions. We skip applyFoldLevel in both cases to preserve
1362+
// IntelliJ's default fold state. The first call has storedValue=null, and the second has both
1363+
// storedValue and newValue as Default - these conditions define initialization.
1364+
if (!isInitializing(storedValue, newValue)) {
1365+
editor.applyFoldLevel(coercedLevel)
1366+
}
13611367

13621368
return storedValue?.value?.value != coercedLevel
13631369
}
1370+
1371+
private fun isInitializing(
1372+
storedValue: OptionValue<VimInt>?,
1373+
newValue: OptionValue<VimInt>,
1374+
): Boolean = storedValue == null ||
1375+
(storedValue is OptionValue.Default && newValue is OptionValue.Default)
13641376
}
13651377

13661378

0 commit comments

Comments
 (0)