You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2010/08/20 15:42:19 UTC

svn commit: r987502 - in /pivot/trunk: wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java wtk/src/org/apache/pivot/wtk/TextInput.java

Author: tvolkert
Date: Fri Aug 20 13:42:18 2010
New Revision: 987502

URL: http://svn.apache.org/viewvc?rev=987502&view=rev
Log:
Reverted text input selection change mods, fixed a fwe other bugs in TextInput and TerraTextInputSkin (validator bugs)

Modified:
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=987502&r1=987501&r2=987502&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Fri Aug 20 13:42:18 2010
@@ -1039,8 +1039,9 @@ public class TerraTextInputSkin extends 
             && character != 0x7F
             && !Keyboard.isPressed(Keyboard.Modifier.META)) {
             TextInput textInput = (TextInput)getComponent();
+            int selectionLength = textInput.getSelectionLength();
 
-            if (textInput.getSelectionLength() == 0
+            if (selectionLength == 0
                 && textInput.getTextLength() == textInput.getMaximumLength()) {
                 Toolkit.getDefaultToolkit().beep();
             } else {
@@ -1049,9 +1050,12 @@ public class TerraTextInputSkin extends 
 
                 if (validator != null
                     && strictValidation) {
-                    StringBuilder buf = new StringBuilder(textInput.getText());
+                    String text = textInput.getText();
                     int selectionStart = textInput.getSelectionStart();
-                    buf.insert(selectionStart, character);
+
+                    StringBuilder buf = new StringBuilder(text.substring(0, selectionStart));
+                    buf.append(character);
+                    buf.append(text.substring(selectionStart + selectionLength));
 
                     if (validator.isValid(buf.toString())) {
                         textInput.insert(character);

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java?rev=987502&r1=987501&r2=987502&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Fri Aug 20 13:42:18 2010
@@ -256,8 +256,7 @@ public class TextInput extends Component
 
             if (selectionStart != previousSelectionStart
                 || selectionLength != previousSelectionLength) {
-                textInputSelectionListeners.selectionChanged(this, previousSelectionStart,
-                    previousSelectionLength);
+                textInputSelectionListeners.selectionChanged(this, selectionStart, selectionLength);
             }
         }
     }
@@ -316,7 +315,7 @@ public class TextInput extends Component
 
             // Update the valid flag
             boolean previousTextValid = textValid;
-            textValid = (validator == null) ? true : validator.isValid(text);
+            textValid = (validator == null) ? true : validator.isValid(this.text);
 
             // Fire change events
             textInputTextListeners.charactersInserted(TextInput.this, previousSelectionStart,
@@ -329,8 +328,7 @@ public class TextInput extends Component
 
             if (selectionStart != previousSelectionStart
                 || selectionLength != previousSelectionLength) {
-                textInputSelectionListeners.selectionChanged(this, previousSelectionStart,
-                    previousSelectionLength);
+                textInputSelectionListeners.selectionChanged(this, selectionStart, selectionLength);
             }
         }
     }
@@ -361,10 +359,6 @@ public class TextInput extends Component
                 count = 1;
             }
 
-            // Update the valid flag
-            boolean previousTextValid = textValid;
-            textValid = (validator == null) ? true : validator.isValid(text);
-
             char[] removed = new char[count];
             if (selectionStart < text.length()) {
                 StringBuilder textBuilder = new StringBuilder(text.substring(0, selectionStart));
@@ -373,6 +367,10 @@ public class TextInput extends Component
                 text = textBuilder.toString();
             }
 
+            // Update the valid flag
+            boolean previousTextValid = textValid;
+            textValid = (validator == null) ? true : validator.isValid(text);
+
             // Fire change events
             textInputTextListeners.charactersRemoved(TextInput.this, selectionStart, removed);
             textInputTextListeners.textChanged(TextInput.this, null);
@@ -383,8 +381,7 @@ public class TextInput extends Component
 
             if (selectionStart != previousSelectionStart
                 || selectionLength != previousSelectionLength) {
-                textInputSelectionListeners.selectionChanged(this, previousSelectionStart,
-                    previousSelectionLength);
+                textInputSelectionListeners.selectionChanged(this, selectionStart, selectionLength);
             }
         }
     }