IDEA-89471 Vertical guidelines are drawn incorrectly

This commit is contained in:
Denis.Zhdanov
2012-07-31 08:58:10 +04:00
parent 3af76ff1cc
commit 07a569ad48
2 changed files with 28 additions and 9 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,8 +35,8 @@ import java.util.List;
public abstract class TextEditorHighlightingPass implements HighlightingPass {
public static final TextEditorHighlightingPass[] EMPTY_ARRAY = new TextEditorHighlightingPass[0];
protected final Document myDocument;
protected final Project myProject;
@Nullable protected final Document myDocument;
@NotNull protected final Project myProject;
private final boolean myRunIntentionPassAfter;
private final long myInitialStamp;
private int[] myCompletionPredecessorIds = ArrayUtil.EMPTY_INT_ARRAY;
@@ -81,7 +81,7 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass {
}
if (myDocument != null && myDocument.getModificationStamp() != myInitialStamp) return false;
if (myProject != null && myDocument != null) {
if (myDocument != null) {
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument);
if (file == null || !file.isValid()) return false;
}
@@ -128,6 +128,7 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass {
myCompletionPredecessorIds = completionPredecessorIds;
}
@Nullable
public Document getDocument() {
return myDocument;
}
@@ -331,7 +331,11 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware
}
private boolean isBlankLine(int line, CharSequence chars) {
int startOffset = myDocument.getLineStartOffset(line);
Document document = myDocument;
if (document == null) {
return true;
}
int startOffset = document.getLineStartOffset(line);
return CharArrayUtil.shiftForward(chars, startOffset, " \t") >= myDocument.getLineEndOffset(line);
}
@@ -339,6 +343,7 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware
final Document doc = myDocument;
CharSequence chars = doc.getCharsSequence();
int[] lineIndents = new int[doc.getLineCount()];
boolean[] indentStartedInComment = new boolean[lineIndents.length];
TokenSet comments = LanguageParserDefinitions.INSTANCE.forLanguage(myFile.getLanguage()).getCommentTokens();
int prevColumn = -1;
@@ -353,11 +358,24 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware
int nonWhitespaceOffset = CharArrayUtil.shiftForward(chars, lineStart, " \t");
if (nonWhitespaceOffset < lineEnd) {
final int column = myEditor.calcColumnNumber(nonWhitespaceOffset, line);
if (column < prevColumn) {
if (column != prevColumn) {
final HighlighterIterator it = highlighter.createIterator(nonWhitespaceOffset);
if (comments.contains(it.getTokenType())) {
lineIndents[line] = -1;
continue;
boolean comment = comments.contains(it.getTokenType());
if (column > prevColumn && comment) {
indentStartedInComment[line] = true;
}
else if (column < prevColumn && comment) {
boolean startInComment = false;
for (int i = line - 1; i >= 0 && (lineIndents[i] < 0 || lineIndents[i] >= column); i--) {
if (indentStartedInComment[i]) {
startInComment = true;
break;
}
}
if (!startInComment) {
lineIndents[line] = -1;
continue;
}
}
}