Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Bullen2017-07-24 14:13:26 -0400
committerLucas Bullen2017-07-24 14:26:18 -0400
commit5c8cf37fee9b51ed5761d1de73d1d840d40739e7 (patch)
treecb5ca6ab9aa518106874c1243efb43fe202857a6
parenta07fab236bceb22de2fc243a1a47d5987d9a533d (diff)
downloadeclipse.platform.text-5c8cf37fee9b51ed5761d1de73d1d840d40739e7.tar.gz
eclipse.platform.text-5c8cf37fee9b51ed5761d1de73d1d840d40739e7.tar.xz
eclipse.platform.text-5c8cf37fee9b51ed5761d1de73d1d840d40739e7.zip
Bug 520034 - [GE] Folding reconciler removes folds after editing
- Only remove outdated reconcilers Change-Id: Ie0e2b86cd0b46d75bcdb4c0f7406f551a33b1e48 Signed-off-by: Lucas Bullen <lbullen@redhat.com>
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/FoldingStrategy.java36
1 files changed, 25 insertions, 11 deletions
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/FoldingStrategy.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/FoldingStrategy.java
index 42c36be84..f0d573f4b 100644
--- a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/FoldingStrategy.java
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/FoldingStrategy.java
@@ -30,8 +30,10 @@ import org.eclipse.jface.text.source.projection.ProjectionViewer;
public class FoldingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
private IDocument document;
+ private String oldDocument;
private ProjectionViewer projectionViewer;
- private Annotation[] oldAnnotations;
+ private List<Annotation> oldAnnotations = new ArrayList<>();
+ private List<Position> oldPositions = new ArrayList<>();
@Override
public void setDocument(IDocument document) {
@@ -54,20 +56,32 @@ public class FoldingStrategy implements IReconcilingStrategy, IReconcilingStrate
@Override
public void initialReconcile() {
+ if(document.get().equals(oldDocument)) return;
+ oldDocument = document.get();
+
List<Position> positions = getNewPositionsOfAnnotations();
- Annotation[] annotations = new Annotation[positions.size()];
- HashMap<Annotation, Position> newAnnotations = new HashMap<>();
+ List<Position> positionsToRemove = new ArrayList<>();
+ List<Annotation> annotationToRemove = new ArrayList<>();
- for(int i =0;i<positions.size();i++)
- {
- ProjectionAnnotation annotation = new ProjectionAnnotation();
- newAnnotations.put(annotation,positions.get(i));
- annotations[i]=annotation;
+ for (Position position : oldPositions) {
+ if(!positions.contains(position)) {
+ projectionViewer.getProjectionAnnotationModel().removeAnnotation(oldAnnotations.get(oldPositions.indexOf(position)));
+ positionsToRemove.add(position);
+ annotationToRemove.add(oldAnnotations.get(oldPositions.indexOf(position)));
+ }else {
+ positions.remove(position);
+ }
+ }
+ oldPositions.removeAll(positionsToRemove);
+ oldAnnotations.removeAll(annotationToRemove);
+
+ for (Position position : positions) {
+ Annotation annotation = new ProjectionAnnotation();
+ projectionViewer.getProjectionAnnotationModel().addAnnotation(annotation, position);
+ oldPositions.add(position);
+ oldAnnotations.add(annotation);
}
-
- projectionViewer.getProjectionAnnotationModel().modifyAnnotations(oldAnnotations,newAnnotations,null);
- oldAnnotations=annotations;
}
private static enum SearchingFor {

Back to the top