Hi there, Am 3.11.2005 schrieb "Roman Kennke" <[EMAIL PROTECTED]>:
>Hi Audrius, > >Am Donnerstag, den 03.11.2005, 15:50 +0100 schrieb Meskauskas Audrius: >> Our JTextField contains an "imaginary" end of line character (0xA), but >> the new text must be always inserted before it, not after. When clicking >> right from the last character in the field, the >> PlainTextView.viewToModel should return the position before the end of >> line character and not after the end of line character. Otherwise the >> inputs blocks. If the empty field receives focus by the mouse click, the >> caret position is always set after the 0xA and, a result, it is never >> possible to enter any text in the field. > >Wow, good observations and bug finding. You are right, the Content model >of the PlainDocument contains an imaginary 0xA character at the end. >This should not be exposed via the Document accessor methods, also not >by the viewToModel or getText. Your patch fixes you problem, but at best >hides the real problem, beeing that this newline character is somehow >counted in in getText. > >I can fix this tomorrow. Thanks for this good observations. It looks like your fix was practically correct. I checked the getText() method and it actually should return the final newline character. I simplified your patch a little, in PlainView we can assume that every line ends in a newline (that is possible the whole point of this one implicit newline) and exclude that from the calculation in viewToModel. Also I fixed a little error that sneaked in with one of my previous DefaultCaret patches so caret positioning in JTextFields should now work again. 2005-11-03 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/text/DefaultCaret.java (positionCaret): Call setDot instead of moveDot. * javax/swing/text/PlainView.java (viewToModel): Exclude the final newline character from calculation. /Roman
Index: javax/swing/text/DefaultCaret.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultCaret.java,v retrieving revision 1.21 diff -u -r1.21 DefaultCaret.java --- javax/swing/text/DefaultCaret.java 3 Nov 2005 14:39:37 -0000 1.21 +++ javax/swing/text/DefaultCaret.java 3 Nov 2005 23:18:49 -0000 @@ -449,7 +449,7 @@ protected void positionCaret(MouseEvent event) { int newDot = getComponent().viewToModel(event.getPoint()); - moveDot(newDot); + setDot(newDot); } /** Index: javax/swing/text/PlainView.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v retrieving revision 1.31 diff -u -r1.31 PlainView.java --- javax/swing/text/PlainView.java 3 Nov 2005 19:29:00 -0000 1.31 +++ javax/swing/text/PlainView.java 3 Nov 2005 23:18:49 -0000 @@ -326,17 +326,12 @@ Element line = root.getElement(lineClicked); Segment s = getLineBuffer(); - int start = line.getStartOffset(); - int end = line.getEndOffset(); + // We don't want the \n at the end of the line. + int end = line.getEndOffset() - 1; try { doc.getText(start, end - start, s); - - // The end of line symbol (0xA), if being the last member in the - // obtained text, should not be counted. - if (s.last()==0xA && end>start) - s.count--; } catch (BadLocationException ble) {
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches