This fixes the GapContent for a weird bordercase that Tony filed as

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24105

I also added this to the Mauve testsuite for GapContent.

2005-09-29  Roman Kennke  <[EMAIL PROTECTED]>

        Fixes Bug #24105
        * javax/swing/text/GapContent.java
        (GapContentPosition.getOffset): Adjusted assert statement.
        (shiftGap): Adjusted index in getPositionsInRange call. Call
        resetMarksAtZero if gapStart has moved to 0.
        (replace): Call shiftGap and shiftGapEndUp only if necessary.
        (resetMarksAtZero): New method.

/Roman
Index: javax/swing/text/GapContent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v
retrieving revision 1.26
diff -u -r1.26 GapContent.java
--- javax/swing/text/GapContent.java	13 Sep 2005 23:22:27 -0000	1.26
+++ javax/swing/text/GapContent.java	29 Sep 2005 17:20:30 -0000
@@ -116,7 +116,7 @@
     public int getOffset()
     {
       // Check precondition.
-      assert mark <= gapStart || mark > gapEnd : "mark: " + mark
+      assert mark <= gapStart || mark >= gapEnd : "mark: " + mark
                                                + ", gapStart: " + gapStart
                                                + ", gapEnd: " + gapEnd;
 
@@ -379,7 +379,7 @@
     if (index < 0)
       index = -(index + 1);
     positions.add(index, pos);
-    
+
     return pos;
   }
 
@@ -426,13 +426,12 @@
       return;
 
     int newGapEnd = newGapStart + gapEnd - gapStart;
-
     if (newGapStart < gapStart)
       {
         // Update the positions between newGapStart and (old) gapStart. The marks
         // must be shifted by (gapEnd - gapStart).
-        Vector v = getPositionsInRange(null, newGapStart + 1,
-                                       gapStart - newGapStart + 1);
+        Vector v = getPositionsInRange(null, newGapStart,
+                                       gapStart - newGapStart);
         for (Iterator i = v.iterator(); i.hasNext();)
           {
             GapContentPosition p = (GapContentPosition) i.next();
@@ -459,6 +458,8 @@
         gapStart = newGapStart;
         gapEnd = newGapEnd;
       }
+    if (gapStart == 0)
+      resetMarksAtZero();
   }
 
   /**
@@ -530,9 +531,11 @@
   protected void replace(int position, int rmSize, Object addItems,
                          int addSize)
   {
+    if (gapStart != position)
+      shiftGap(position);
     // Remove content
-    shiftGap(position);
-    shiftGapEndUp(gapEnd + rmSize);
+    if (rmSize > 0)
+      shiftGapEndUp(gapEnd + rmSize);
 
     // If gap is too small, enlarge the gap.
     if ((gapEnd - gapStart) <= addSize)
@@ -604,5 +607,24 @@
           res.add(p);
       }
     return res;
+  }
+
+  /**
+   * Resets all <code>Position</code> that have an offset of <code>0</code>,
+   * to also have an array index of <code>0</code>. This might be necessary
+   * after a call to <code>shiftGap(0)</code>, since then the marks at offset
+   * <code>0</code> get shifted to <code>gapEnd</code>.
+   */
+  protected void resetMarksAtZero()
+  {
+    if (gapStart != 0)
+      return;
+
+    Vector zeroMarks = getPositionsInRange(null, gapEnd, 0);
+    for (Iterator i = zeroMarks.iterator(); i.hasNext();)
+      {
+        GapContentPosition pos = (GapContentPosition) i.next();
+        pos.mark = 0;
+      }
   }
 }
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to