diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java index 81c49caebc83..f0c7f7f27d59 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java @@ -153,8 +153,16 @@ class UpdateFoldRegionsOperation implements Runnable { if (caretOffset > myEditor.getDocument().getTextLength()) { return false; } - final int currentLine = document.getLineNumber(caretOffset); - caretInside = firstLine <= currentLine && currentLine <= lastLine; + if (caretOffset == 0 && myApplyDefaultState) { + // Caret is located at the zero position when the editor is just opened, so, any fold region that starts at the zero + // offset (e.g. file header provided by 'copyright' plugin) is always expanded. We want to avoid that, hence, corresponding + // control flow branch is introduced. + caretInside = false; + } + else { + final int currentLine = document.getLineNumber(caretOffset); + caretInside = firstLine <= currentLine && currentLine <= lastLine; + } } if (myApplyDefaultState) {