mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-156735 Bookmarks causing typing slowness
This commit is contained in:
@@ -49,17 +49,19 @@ import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.reference.SoftReference;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.RetrievableIcon;
|
||||
import com.intellij.util.NotNullProducer;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.WeakHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class Bookmark implements Navigatable, Comparable<Bookmark> {
|
||||
public static final Icon DEFAULT_ICON = new MyCheckedIcon();
|
||||
@@ -67,6 +69,7 @@ public class Bookmark implements Navigatable, Comparable<Bookmark> {
|
||||
private final VirtualFile myFile;
|
||||
@NotNull private OpenFileDescriptor myTarget;
|
||||
private final Project myProject;
|
||||
private WeakHashMap<Document, Reference<RangeHighlighterEx>> myHighlighterRefs;
|
||||
|
||||
private String myDescription;
|
||||
private char myMnemonic = 0;
|
||||
@@ -106,33 +109,37 @@ public class Bookmark implements Navigatable, Comparable<Bookmark> {
|
||||
}
|
||||
|
||||
public RangeHighlighter createHighlighter(@NotNull MarkupModelEx markup) {
|
||||
final RangeHighlighterEx myHighlighter;
|
||||
final RangeHighlighterEx highlighter;
|
||||
int line = getLine();
|
||||
if (line >= 0) {
|
||||
myHighlighter = markup.addPersistentLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
|
||||
if (myHighlighter != null) {
|
||||
myHighlighter.setGutterIconRenderer(new MyGutterIconRenderer(this));
|
||||
highlighter = markup.addPersistentLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
|
||||
if (highlighter != null) {
|
||||
highlighter.setGutterIconRenderer(new MyGutterIconRenderer(this));
|
||||
|
||||
TextAttributes textAttributes =
|
||||
EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BOOKMARKS_ATTRIBUTES);
|
||||
|
||||
Color stripeColor = textAttributes.getErrorStripeColor();
|
||||
myHighlighter.setErrorStripeMarkColor(stripeColor != null ? stripeColor : Color.black);
|
||||
myHighlighter.setErrorStripeTooltip(getBookmarkTooltip());
|
||||
highlighter.setErrorStripeMarkColor(stripeColor != null ? stripeColor : Color.black);
|
||||
highlighter.setErrorStripeTooltip(getBookmarkTooltip());
|
||||
|
||||
TextAttributes attributes = myHighlighter.getTextAttributes();
|
||||
TextAttributes attributes = highlighter.getTextAttributes();
|
||||
if (attributes == null) {
|
||||
attributes = new TextAttributes();
|
||||
}
|
||||
attributes.setBackgroundColor(textAttributes.getBackgroundColor());
|
||||
attributes.setForegroundColor(textAttributes.getForegroundColor());
|
||||
myHighlighter.setTextAttributes(attributes);
|
||||
highlighter.setTextAttributes(attributes);
|
||||
}
|
||||
}
|
||||
else {
|
||||
myHighlighter = null;
|
||||
highlighter = null;
|
||||
}
|
||||
return myHighlighter;
|
||||
if (myHighlighterRefs == null) myHighlighterRefs = new WeakHashMap<>();
|
||||
if (highlighter != null) {
|
||||
myHighlighterRefs.put(markup.getDocument(), new WeakReference<RangeHighlighterEx>(highlighter));
|
||||
}
|
||||
return highlighter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -141,24 +148,33 @@ public class Bookmark implements Navigatable, Comparable<Bookmark> {
|
||||
}
|
||||
|
||||
public void release() {
|
||||
int line = getLine();
|
||||
if (line < 0) {
|
||||
return;
|
||||
}
|
||||
final Document document = getDocument();
|
||||
if (document == null) return;
|
||||
MarkupModelEx markup = (MarkupModelEx)DocumentMarkupModel.forDocument(document, myProject, true);
|
||||
final Document markupDocument = markup.getDocument();
|
||||
if (markupDocument.getLineCount() <= line) return;
|
||||
RangeHighlighterEx highlighter = findMyHighlighter();
|
||||
if (highlighter != null) {
|
||||
highlighter.dispose();
|
||||
try {
|
||||
int line = getLine();
|
||||
if (line < 0) {
|
||||
return;
|
||||
}
|
||||
final Document document = getDocument();
|
||||
if (document == null) return;
|
||||
MarkupModelEx markup = (MarkupModelEx)DocumentMarkupModel.forDocument(document, myProject, true);
|
||||
final Document markupDocument = markup.getDocument();
|
||||
if (markupDocument.getLineCount() <= line) return;
|
||||
RangeHighlighterEx highlighter = findMyHighlighter();
|
||||
if (highlighter != null) {
|
||||
highlighter.dispose();
|
||||
}
|
||||
} finally {
|
||||
myHighlighterRefs = null;
|
||||
}
|
||||
}
|
||||
|
||||
private RangeHighlighterEx findMyHighlighter() {
|
||||
final Document document = getDocument();
|
||||
if (document == null) return null;
|
||||
Reference<RangeHighlighterEx> reference = myHighlighterRefs != null ? myHighlighterRefs.get(document) : null;
|
||||
RangeHighlighterEx result = SoftReference.dereference(reference);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
MarkupModelEx markup = (MarkupModelEx)DocumentMarkupModel.forDocument(document, myProject, true);
|
||||
final Document markupDocument = markup.getDocument();
|
||||
final int startOffset = 0;
|
||||
@@ -173,7 +189,12 @@ public class Bookmark implements Navigatable, Comparable<Bookmark> {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return found.get();
|
||||
result = found.get();
|
||||
if (result != null) {
|
||||
if (myHighlighterRefs == null) myHighlighterRefs = new WeakHashMap<>();
|
||||
myHighlighterRefs.put(document, new WeakReference<RangeHighlighterEx>(result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
|
||||
Reference in New Issue
Block a user