From 568003a86babf63f8134140c4ca2c925bb4f601c Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Mon, 22 Aug 2011 17:53:57 +0400 Subject: [PATCH] IDEA-72690 Auto Collapse File Header Code Folding seems broken Corrected 'expanded' folding state processing for the regions that start at the zero offset --- .../folding/impl/UpdateFoldRegionsOperation.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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) {