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

svn commit: r990139 - /pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java

Author: gbrown
Date: Fri Aug 27 13:15:38 2010
New Revision: 990139

URL: http://svn.apache.org/viewvc?rev=990139&view=rev
Log:
Minor fixes to TextInput.

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java

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=990139&r1=990138&r2=990139&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 27 13:15:38 2010
@@ -306,12 +306,12 @@ public class TextInput extends Component
             throw new IllegalArgumentException("Insertion of text would exceed maximum length.");
         }
 
-        // Insert the text
         if (text.length() > 0) {
             Vote vote = textInputContentListeners.previewInsertText(this, text, index);
 
             if (vote == Vote.APPROVE) {
-                characters.insert(selectionStart, text);
+                // Insert the text
+                characters.insert(index, text);
 
                 // Update selection
                 int previousSelectionStart = selectionStart;
@@ -342,11 +342,11 @@ public class TextInput extends Component
     }
 
     public void removeText(int index, int count) {
-        // Remove the text
         if (count > 0) {
             Vote vote = textInputContentListeners.previewRemoveText(this, index, count);
 
             if (vote == Vote.APPROVE) {
+                // Remove the text
                 characters.delete(index, index + count);
 
                 // Update the selection
@@ -591,14 +591,21 @@ public class TextInput extends Component
         int previousMaximumLength = this.maximumLength;
 
         if (previousMaximumLength != maximumLength) {
+            int previousTextLength = characters.length();
+
+            this.maximumLength = maximumLength;
+
             // Truncate the text, if necessary
-            int characterCount = characters.length();
-            if (characterCount > maximumLength) {
-                characters.delete(maximumLength, characterCount);
+            if (previousTextLength > maximumLength) {
+                characters.delete(maximumLength, previousTextLength);
             }
 
-            this.maximumLength = maximumLength;
+            // Fire change events
             textInputListeners.maximumLengthChanged(this, previousMaximumLength);
+
+            if (characters.length() != previousTextLength) {
+                textInputContentListeners.textChanged(this);
+            }
         }
     }