[hg] main-silver: #236045: only leaf folds may be shifted. Diagn...

  • From: Svata Dedic < >
  • To:
  • Subject: [hg] main-silver: #236045: only leaf folds may be shifted. Diagn...
  • Date: Tue, 17 Sep 2013 17:28:19 -0700

changeset a049f66cb27c in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/a049f66cb27c
description:
        #236045: only leaf folds may be shifted. Diagnostics extended

diffstat:

 editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java      |   
7 ++-
 editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java |  
20 ++++++++--
 2 files changed, 21 insertions(+), 6 deletions(-)

diffs (94 lines):

diff --git 
a/editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java 
b/editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java
--- a/editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java
+++ b/editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java
@@ -259,14 +259,17 @@
         if (folds.length > 0) {
             int ps = parent.getStartOffset();
             int pe = parent.getEndOffset();
-            int fs = folds[0].getStartOffset();
-            int fe = folds[folds.length - 1].getEndOffset();
+            for (Fold f : folds) {
+                int fs = f.getStartOffset();
+                int fe = f.getEndOffset();
             if (fs < ps || fe > pe) {
                 LOG.log(Level.WARNING, "Illegal attempt to insert fold. 
Parent fold: {0}, folds to be inserted: {1}, " +
                         "at index {2}", new Object[] {
                     parent, Arrays.asList(folds), index
                 });
                 LOG.log(Level.WARNING, "Dumping hierarchy: " + 
parent.getHierarchy(), new Throwable());
+                    break;
+                }
             }
         }
 
diff --git 
a/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java 
b/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
--- a/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
+++ b/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
@@ -602,7 +602,13 @@
             if (next == null) {
                 return true;
             }
-            return next.getStart() != f.getStartOffset() || next.getEnd() != 
f.getEndOffset();
+            // do not attempt to resize non-leaf folds; the shifting feature 
is
+            // intentionally used only in import and include - like blocks, 
they are
+            // both leaf. If non-leaf folds should update/resize, checks 
must be put
+            // that they still fit into the parent's hierarchy and if not, 
all parent's
+            // deep-children have to be re-inserted (folds might cross after 
update)
+            return next.getStart() > i.getEnd();
+
         }
         
         private boolean containsSame(FoldInfo i, Fold f) {
@@ -649,7 +655,6 @@
                         continue;
                     }
 
-                    update(f, i);
                     currentFolds.put(i, f);
                     i = ni();
                     f = foldIt.hasNext() ? foldIt.next() : null;
@@ -665,6 +670,11 @@
                         removeFromHierarchy(fold, tran);
                     }
                 }
+                for (Map.Entry<FoldInfo, Fold> updateEntry : 
currentFolds.entrySet()) {
+                    FoldInfo fi = updateEntry.getKey();
+                    Fold ff = updateEntry.getValue();
+                    update(ff, fi);
+                }
                 for (FoldInfo info : toAdd) {
                     try {
                         if (info.getStart() > len || info.getEnd() > len) {
@@ -717,6 +727,7 @@
         public Fold update(Fold f, FoldInfo info) throws 
BadLocationException {
             this.fsch = null;
             int soffs = f.getStartOffset();
+            int origStart = soffs;
             ApiPackageAccessor acc = getAccessor();
             int len = getDocument().getLength();
             if (info.getStart() > len || info.getEnd() > len) {
@@ -734,6 +745,7 @@
                 soffs = info.getStart();
             }
             int eoffs = f.getEndOffset();
+            int origEnd = eoffs;
             if (info.getEnd() != eoffs) {
                 FoldStateChange state = getFSCH(f);
                 if (state.getOriginalStartOffset()>= 0 && 
state.getOriginalStartOffset() > eoffs) {
@@ -761,14 +773,14 @@
                         Fold prev = p.getFold(index - 1);
                         if (prev.getEndOffset() > f.getStartOffset()) {
                             LOG.warning("Wrong fold nesting after update, 
hierarchy: " + execution);
-                            LOG.warning("FoldInfo: " + info + ", fold: " + f 
+ " origStart-End" + soffs + "-" + eoffs);
+                            LOG.warning("FoldInfo: " + info + ", fold: " + f 
+ " origStart-End" + origStart + "-" + origEnd);
                         }
                     }
                     if (index < p.getFoldCount() - 1) {
                         Fold next = p.getFold(index + 1);
                         if (next.getStartOffset() < f.getEndOffset()) {
                             LOG.warning("Wrong fold nesting after update, 
hierarchy: " + execution);
-                            LOG.warning("FoldInfo: " + info + ", fold: " + f 
+ " origStart-End" + soffs + "-" + eoffs);
+                            LOG.warning("FoldInfo: " + info + ", fold: " + f 
+ " origStart-End" + origStart + "-" + origEnd);
                         }
                     }
                 }

[hg] main-silver: #236045: only leaf folds may be shifted. Diagn...

Svata Dedic 09/18/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close