mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
LexerEditorHighlighter: do nothing in setText if the text is identical to the previous one
This commit is contained in:
+8
-9
@@ -47,7 +47,6 @@ import java.util.*;
|
||||
public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter {
|
||||
private final Map<IElementType, LayerDescriptor> myTokensToLayer = new HashMap<>();
|
||||
private final Map<LayerDescriptor, Mapper> myLayerBuffers = new HashMap<>();
|
||||
private CharSequence myText;
|
||||
|
||||
public LayeredLexerEditorHighlighter(@NotNull SyntaxHighlighter highlighter, @NotNull EditorColorsScheme scheme) {
|
||||
super(highlighter, scheme);
|
||||
@@ -120,7 +119,6 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter {
|
||||
// do NOT synchronize before updateLayers due to deadlock with PsiLock
|
||||
updateLayers();
|
||||
|
||||
myText = text;
|
||||
super.setText(text);
|
||||
}
|
||||
|
||||
@@ -158,12 +156,11 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter {
|
||||
@Override
|
||||
public void documentChanged(DocumentEvent e) {
|
||||
// do NOT synchronize before updateLayers due to deadlock with PsiLock
|
||||
final boolean b = updateLayers();
|
||||
boolean changed = updateLayers();
|
||||
|
||||
synchronized (this) {
|
||||
myText = e.getDocument().getCharsSequence();
|
||||
if (b) {
|
||||
setText(myText);
|
||||
if (changed) {
|
||||
setText(e.getDocument().getImmutableCharSequence());
|
||||
}
|
||||
else {
|
||||
super.documentChanged(e);
|
||||
@@ -175,11 +172,13 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter {
|
||||
@Override
|
||||
public HighlighterIterator createIterator(int startOffset) {
|
||||
// do NOT synchronize before updateLayers due to deadlock with PsiLock
|
||||
final boolean b = updateLayers();
|
||||
final boolean changed = updateLayers();
|
||||
|
||||
synchronized (this) {
|
||||
if (b) {
|
||||
setText(myText);
|
||||
if (changed) {
|
||||
CharSequence text = myText;
|
||||
myText = null;
|
||||
setText(text);
|
||||
}
|
||||
return new LayeredHighlighterIteratorImpl(startOffset);
|
||||
}
|
||||
|
||||
+10
-3
@@ -37,6 +37,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.text.ImmutableCharSequence;
|
||||
import com.intellij.util.text.ImmutableText;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -54,6 +55,7 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc
|
||||
private final SyntaxHighlighter myHighlighter;
|
||||
private EditorColorsScheme myScheme;
|
||||
private final int myInitialState;
|
||||
protected CharSequence myText;
|
||||
|
||||
public LexerEditorHighlighter(@NotNull SyntaxHighlighter highlighter, @NotNull EditorColorsScheme scheme) {
|
||||
myScheme = scheme;
|
||||
@@ -112,7 +114,7 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc
|
||||
if(document instanceof DocumentEx && ((DocumentEx)document).isInBulkUpdate()) {
|
||||
((DocumentEx)document).setInBulkUpdate(false); // bulk mode failed
|
||||
}
|
||||
doSetText(document.getCharsSequence());
|
||||
doSetText(document.getImmutableCharSequence());
|
||||
}
|
||||
|
||||
final int latestValidOffset = mySegments.getLastValidOffset();
|
||||
@@ -147,18 +149,20 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc
|
||||
public synchronized void documentChanged(DocumentEvent e) {
|
||||
try {
|
||||
final Document document = e.getDocument();
|
||||
CharSequence text = document.getImmutableCharSequence();
|
||||
|
||||
if (document instanceof DocumentEx && ((DocumentEx)document).isInBulkUpdate()) {
|
||||
myText = null;
|
||||
mySegments.removeAll();
|
||||
return;
|
||||
}
|
||||
|
||||
if(mySegments.getSegmentCount() == 0) {
|
||||
setText(document.getCharsSequence());
|
||||
setText(text);
|
||||
return;
|
||||
}
|
||||
|
||||
CharSequence text = document.getCharsSequence();
|
||||
myText = text;
|
||||
int oldStartOffset = e.getOffset();
|
||||
|
||||
final int segmentIndex = mySegments.findSegmentIndex(oldStartOffset) - 2;
|
||||
@@ -312,6 +316,9 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc
|
||||
}
|
||||
|
||||
private void doSetText(final CharSequence text) {
|
||||
if (Comparing.equal(myText, text)) return;
|
||||
myText = ImmutableCharSequence.asImmutable(text);
|
||||
|
||||
final TokenProcessor processor = createTokenProcessor(0);
|
||||
final int textLength = text.length();
|
||||
myLexer.start(text, 0, textLength, myInitialState);
|
||||
|
||||
Reference in New Issue
Block a user