[g-a-devel] [PATCH] java-access-bridge: dont throw exceptions when entering text in AWT TextField


When using an AWT TextField to type text in, the property change emitted by the TextField is different from that of a JTextField. In the case of TextField, the newValueObject seen by JavaBridge.dispatchTextProperty is an Integer containing the new position of the caret, not the position at which text was inserted. This patch fixes newValueObject to contain the index of insertion. It also sets oldFocusText before using it. This fixes the StringIndexOutOfBoundException and emits the proper index for the object:text-changed:insert event.


Index: bridge/org/GNOME/Accessibility/JavaBridge.java
--- bridge/org/GNOME/Accessibility/JavaBridge.java	(revision 232)
+++ bridge/org/GNOME/Accessibility/JavaBridge.java	(working copy)
@@ -745,11 +745,16 @@
 			    oldFocusText = aeText.getTextRange (0, charCount);
 		    else if ((ac != null) && (ac == oldFocusSource)) {
+			// accessibleAWTTextComponent
+			// the event fired by the text component is different from what we expect
+			// newValueObject is not the position of the insertion, 
+			// but the position of the caret after the instertion, so fix newValueObject
+			newValueObject = new Integer(((Integer)newValueObject).intValue() - oldValue);
+			oldFocusText = getTextRange (aText, 0, charCount);
 			any.insert_string (oldFocusText.substring (
 				       ((Integer)newValueObject).intValue() + 
-			oldFocusText = getTextRange (aText, 0, charCount);
                 else if ( charCount < prevCharCount ) {

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