Skip to content

Commit f254d43

Browse files
tobias-melcherBeckerWdf
authored andcommitted
position of code mining annotation need to be removed with delay
to fix issue #3121
1 parent 418d9e0 commit f254d43

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractMarkerAnnotationModel.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import org.osgi.framework.Bundle;
2424

25+
import org.eclipse.swt.widgets.Display;
26+
2527
import org.eclipse.core.runtime.Assert;
2628
import org.eclipse.core.runtime.CoreException;
2729
import org.eclipse.core.runtime.IConfigurationElement;
@@ -42,6 +44,7 @@
4244
import org.eclipse.jface.text.source.Annotation;
4345
import org.eclipse.jface.text.source.AnnotationModel;
4446
import org.eclipse.jface.text.source.IAnnotationMap;
47+
import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;
4548

4649
import org.eclipse.ui.PlatformUI;
4750
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
@@ -706,4 +709,45 @@ public void revert(IDocument document) {
706709
public void reinitialize(IDocument document) {
707710
resetMarkers();
708711
}
712+
713+
private final ThreadLocal<Annotation> currentToBeDeletedAnnotation = new ThreadLocal<>();
714+
715+
@Override
716+
protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) {
717+
currentToBeDeletedAnnotation.set(annotation);
718+
try {
719+
super.removeAnnotation(annotation, fireModelChanged);
720+
} finally {
721+
currentToBeDeletedAnnotation.remove();
722+
}
723+
}
724+
725+
@Override
726+
protected void removePosition(IDocument document, Position position) {
727+
if (removePositionOfCodeMiningAnnotationDelayedInMainThread(document, position)) {
728+
return;
729+
}
730+
super.removePosition(document, position);
731+
}
732+
733+
private boolean removePositionOfCodeMiningAnnotationDelayedInMainThread(IDocument document, Position position) {
734+
Annotation annotation = currentToBeDeletedAnnotation.get();
735+
if (annotation == null) {
736+
return false;
737+
}
738+
String type = annotation.getType();
739+
if (!AbstractInlinedAnnotation.TYPE.equals(type)) {
740+
return false;
741+
}
742+
IAnnotationMap map = getAnnotationMap();
743+
if (map == null) {
744+
return false;
745+
}
746+
Position pos = map.get(annotation);
747+
if (pos != null && pos.equals(position)) {
748+
Display.getDefault().asyncExec(() -> super.removePosition(document, position));
749+
return true;
750+
}
751+
return false;
752+
}
709753
}

0 commit comments

Comments
 (0)