Now that Lillian and I have good documentation for the ElementBuffer class (http://java.sun.com/products/jfc/tsc/articles/text/element_buffer/index.html) we can finally nail this class down and get it right.
I coded some examples suggested in the document linked above and made the following change. The examples I coded will be turned into Mauve tests and committed. 2006-01-09 Anthony Balkissoon <[EMAIL PROTECTED]> * javax/swing/text/DefaultStyledDocument.java: (insertUpdate): Removed call to checkForInsertAfterNewline and instead inlined this method because it needs to change the value of the finalStartTag and finalStartDirection variables. (checkForInsertAfterNewline): Removed this method. (handleInsertAfterNewline): Added case for making the start tag's direction JoinNextDirection. --Tony
? include/gnu_java_net_PlainDatagramSocketImpl.h ? include/gnu_java_net_PlainSocketImpl.h Index: javax/swing/text/DefaultStyledDocument.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v retrieving revision 1.26 diff -u -r1.26 DefaultStyledDocument.java --- javax/swing/text/DefaultStyledDocument.java 5 Jan 2006 20:15:34 -0000 1.26 +++ javax/swing/text/DefaultStyledDocument.java 9 Jan 2006 18:53:51 -0000 @@ -1596,9 +1596,36 @@ int segmentEnd = txt.offset + txt.count; // Check to see if we're inserting immediately after a newline. - checkForInsertAfterNewline(offset, endOffset, prevParagraph, paragraph, - paragraphAttributes, prevCharWasNewline, - finalStartTag, finalStartDirection, specs); + if (offset > 0) + { + try + { + String s = getText(offset - 1, 1); + if (s.equals("\n")) + { + finalStartDirection = + handleInsertAfterNewline(specs, offset, endOffset, + prevParagraph, + paragraph, + paragraphAttributes); + + prevCharWasNewline = true; + // Find the final start tag from the ones just created. + for (int i = 0; i < specs.size(); i++) + if (((ElementSpec) specs.get(i)).getType() + == ElementSpec.StartTagType) + finalStartTag = (ElementSpec)specs.get(i); + } + } + catch (BadLocationException ble) + { + // This shouldn't happen. + AssertionError ae = new AssertionError(); + ae.initCause(ble); + throw ae; + } + } + for (int i = txt.offset; i < segmentEnd; ++i) { @@ -1663,49 +1690,6 @@ } /** - * A helper method that checks to see if insertUpdate was called when text - * was inserted immediately after a newline, and calls - * handleInsertAfterNewline if that is the case. - */ - void checkForInsertAfterNewline(int offset, int endOffset, - Element prevParagraph, Element paragraph, - AttributeSet paragraphAttributes, - boolean prevCharWasNewline, - ElementSpec finalStartTag, - short finalStartDirection, Vector specs) - { - if (offset > 0) - { - try - { - String s = getText(offset - 1, 1); - if (s.equals("\n")) - { - finalStartDirection = - handleInsertAfterNewline(specs, offset, endOffset, - prevParagraph, - paragraph, - paragraphAttributes); - - prevCharWasNewline = true; - // Find the final start tag from the ones just created. - for (int i = 0; i < specs.size(); i++) - if (((ElementSpec) specs.get(i)).getType() - == ElementSpec.StartTagType) - finalStartTag = (ElementSpec)specs.get(i); - } - } - catch (BadLocationException ble) - { - // This shouldn't happen. - AssertionError ae = new AssertionError(); - ae.initCause(ble); - throw ae; - } - } - } - - /** * A helper method to set up the ElementSpec buffer for the special * case of an insertion occurring immediately after a newline. * @param specs the ElementSpec buffer to initialize. @@ -1720,7 +1704,10 @@ specs.add(new ElementSpec(a, ElementSpec.StartTagType)); if (prevParagraph.getEndOffset() != endOffset) return ElementSpec.JoinFractureDirection; - + // If there is an Element after this one, use JoinNextDirection. + Element parent = paragraph.getParentElement(); + if (parent.getElementCount() > parent.getElementIndex(offset) + 1) + return ElementSpec.JoinNextDirection; } else {
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches