[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] RFC: Suggested change in PlainView.
From: |
Meskauskas Audrius |
Subject: |
[cp-patches] RFC: Suggested change in PlainView. |
Date: |
Thu, 03 Nov 2005 15:50:21 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Windows/20050317) |
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.
The bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24650 has the
uploaded test case, demonstrating this problem.
This path fixes the problem by introducing the following rule: if the
last character under the mouse click is 0xA, it should not be taken into
consideration, the pre-last character must be returned instead (the 0xA
is a dimensionless character anyway).
With this patch, I "revived" the text fields in my application. In the
swing activity board, now it is possible to enter the text after
clicking the mouse RIGHT from the "Hello world" in the text field demo.
The work of the rest of Swing seems not broken, despite it would be nice
if somebody else could check this as well.
2005-11-03 Audrius Meskauskas <address@hidden>
PR swing/24650
* javax/swing/text/PlainView.java (viewToModel)):
The end of line symbol (0xA), if being the last member in the obtained
text, should not be counted.
Index: javax/swing/text/PlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v
retrieving revision 1.29
diff -u -r1.29 PlainView.java
--- javax/swing/text/PlainView.java 30 Oct 2005 22:03:50 -0000 1.29
+++ javax/swing/text/PlainView.java 3 Nov 2005 14:13:50 -0000
@@ -329,15 +329,20 @@
int start = line.getStartOffset();
int end = line.getEndOffset();
try
- {
- doc.getText(start, end - start, s);
- }
+ {
+ 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)
- {
- AssertionError ae = new AssertionError("Unexpected bad location");
- ae.initCause(ble);
- throw ae;
- }
+ {
+ AssertionError ae = new AssertionError("Unexpected bad location");
+ ae.initCause(ble);
+ throw ae;
+ }
int pos = Utilities.getTabbedTextOffset(s, metrics, rec.x, (int)x, this,
start);
return Math.max (0, pos);
- [cp-patches] RFC: Suggested change in PlainView.,
Meskauskas Audrius <=