|
22 | 22 |
|
23 | 23 | import org.osgi.framework.Bundle;
|
24 | 24 |
|
| 25 | +import org.eclipse.swt.widgets.Display; |
| 26 | + |
25 | 27 | import org.eclipse.core.runtime.Assert;
|
26 | 28 | import org.eclipse.core.runtime.CoreException;
|
27 | 29 | import org.eclipse.core.runtime.IConfigurationElement;
|
|
42 | 44 | import org.eclipse.jface.text.source.Annotation;
|
43 | 45 | import org.eclipse.jface.text.source.AnnotationModel;
|
44 | 46 | import org.eclipse.jface.text.source.IAnnotationMap;
|
| 47 | +import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation; |
45 | 48 |
|
46 | 49 | import org.eclipse.ui.PlatformUI;
|
47 | 50 | import org.eclipse.ui.internal.editors.text.EditorsPlugin;
|
@@ -706,4 +709,45 @@ public void revert(IDocument document) {
|
706 | 709 | public void reinitialize(IDocument document) {
|
707 | 710 | resetMarkers();
|
708 | 711 | }
|
| 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 | + } |
709 | 753 | }
|
0 commit comments