From 17ff674fa813d3836bef645a5b15a8e96297e1f4 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Thu, 31 May 2018 19:18:03 +0300 Subject: [PATCH] IDEA-186750 Indent guides often disappear --- .../codeInsight/daemon/impl/IndentsPass.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java index 8f820559dee7..ad98350d8a4b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. /* * @author max @@ -45,10 +43,8 @@ import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NotNull; import java.awt.*; -import java.util.ArrayList; -import java.util.Collections; +import java.util.*; import java.util.List; -import java.util.Map; public class IndentsPass extends TextEditorHighlightingPass implements DumbAware { private static final Key> INDENT_HIGHLIGHTERS_IN_EDITOR_KEY = Key.create("INDENT_HIGHLIGHTERS_IN_EDITOR_KEY"); @@ -228,10 +224,14 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware int curRange = 0; if (oldHighlighters != null) { + // after document change some range highlighters could have become invalid, or the order could have been broken + oldHighlighters.sort(Comparator.comparing((RangeHighlighter h) -> !h.isValid()) + .thenComparing(Segment.BY_START_OFFSET_THEN_END_OFFSET)); int curHighlight = 0; while (curRange < myRanges.size() && curHighlight < oldHighlighters.size()) { TextRange range = myRanges.get(curRange); RangeHighlighter highlighter = oldHighlighters.get(curHighlight); + if (!highlighter.isValid()) break; int cmp = compare(range, highlighter); if (cmp < 0) { @@ -251,6 +251,7 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware for (; curHighlight < oldHighlighters.size(); curHighlight++) { RangeHighlighter highlighter = oldHighlighters.get(curHighlight); + if (!highlighter.isValid()) break; highlighter.dispose(); } }