classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Fix indices in text buffer access in javax.swing.text


From: Roman Kennke
Subject: [cp-patches] FYI: Fix indices in text buffer access in javax.swing.text
Date: Fri, 03 Jun 2005 16:29:25 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204

There have been an error in text buffer access in javax.swing.text which cause the bug https://savannah.gnu.org/bugs/?func=detailitem&item_id=13262

This is fixed by the attached patch.

2005-06-03  Roman Kennke  <address@hidden>

   * javax/swing/text/PlainDocument.java
   (removeUpdate): Fixed indices in text buffer access.
   * javax/swing/text/PlainView.java
   (drawLine): Simplified element access.

/Roman

Index: PlainDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainDocument.java,v
retrieving revision 1.10
diff -u -r1.10 PlainDocument.java
--- PlainDocument.java  1 Jun 2005 09:28:24 -0000       1.10
+++ PlainDocument.java  3 Jun 2005 14:25:24 -0000
@@ -117,8 +117,8 @@
     super.removeUpdate(event);
 
     int p0 = event.getOffset();
-    int p1 = event.getLength() + p0;
     int len = event.getLength();
+    int p1 = len + p0;
 
     // check if we must collapse some elements
     int i1 = rootElement.getElementIndex(p0);
@@ -133,7 +133,7 @@
         Element newEl = createLeafElement(rootElement,
                                           SimpleAttributeSet.EMPTY,
                                           start, end - len);
-        rootElement.replace(i1, i1 - i1, new Element[]{ newEl });
+        rootElement.replace(i1, i2 - i1, new Element[]{ newEl });
       }
     else
       {
Index: PlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v
retrieving revision 1.7
diff -u -r1.7 PlainView.java
--- PlainView.java      6 May 2005 10:31:59 -0000       1.7
+++ PlainView.java      3 Jun 2005 14:25:25 -0000
@@ -123,7 +123,7 @@
       {
        metrics = g.getFontMetrics();
        // FIXME: Selected text are not drawn yet.
-       Element line = 
getDocument().getDefaultRootElement().getElement(lineIndex);
+       Element line = getElement().getElement(lineIndex);
        drawUnselectedText(g, x, y, line.getStartOffset(), line.getEndOffset());
        //drawSelectedText(g, , , , );
       }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]