I fixed the binarySearches in GapContent to really find the first
position in the case when there are multiple positions with the same
offset. The problem is that the binary search cannot make guarantees
which element is found in this case.

2005-11-23  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/GapContent.java
        (getPostionsInRange): Fixed binarySearch to really find the first
        position in this range.
        (setPostionsInRange): Fixed binarySearch to really find the first
        position in this range.
        (adjustPostionsInRange): Fixed binarySearch to really find the
first
        position in this range.

/Roman
Index: javax/swing/text/GapContent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v
retrieving revision 1.32
diff -u -r1.32 GapContent.java
--- javax/swing/text/GapContent.java	11 Oct 2005 20:14:22 -0000	1.32
+++ javax/swing/text/GapContent.java	23 Nov 2005 12:01:20 -0000
@@ -100,15 +100,15 @@
     public int compareTo(Object o)
     {
       if (o instanceof Integer)
-      {
-        int otherMark = ((Integer) o).intValue();
-        return mark - otherMark;
-      }
+        {
+          int otherMark = ((Integer) o).intValue();
+          return mark - otherMark;
+        }
       else
-      {
-        GapContentPosition other = (GapContentPosition) o;
-        return mark - other.mark;
-      }
+        {
+          GapContentPosition other = (GapContentPosition) o;
+          return mark - other.mark;
+        }
     }
 
     /**
@@ -644,6 +644,13 @@
                                           new GapContentPosition(offset));
     if (index1 < 0)
       index1 = -(index1 + 1);
+
+    // Search the first index with the specified offset. The binarySearch does
+    // not necessarily find the first one.
+    while (index1 > 0
+        && ((GapContentPosition) positions.get(index1 - 1)).mark == offset)
+      index1--;
+
     for (ListIterator i = positions.listIterator(index1); i.hasNext();)
       {
         GapContentPosition p = (GapContentPosition) i.next();
@@ -672,6 +679,13 @@
                                           new GapContentPosition(offset));
     if (index1 < 0)
       index1 = -(index1 + 1);
+
+    // Search the first index with the specified offset. The binarySearch does
+    // not necessarily find the first one.
+    while (index1 > 0
+        && ((GapContentPosition) positions.get(index1 - 1)).mark == offset)
+      index1--;
+
     for (ListIterator i = positions.listIterator(index1); i.hasNext();)
       {
         GapContentPosition p = (GapContentPosition) i.next();
@@ -700,6 +714,12 @@
                                           new GapContentPosition(offset));
     if (index1 < 0)
       index1 = -(index1 + 1);
+
+    // Search the first index with the specified offset. The binarySearch does
+    // not necessarily find the first one.
+    while (index1 > 0
+        && ((GapContentPosition) positions.get(index1 - 1)).mark == offset)
+      index1--;
     for (ListIterator i = positions.listIterator(index1); i.hasNext();)
       {
         GapContentPosition p = (GapContentPosition) i.next();
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to