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 2009/10/27 22:28:18 UTC

svn commit: r830348 - in /incubator/pivot/trunk/wtk: src/org/apache/pivot/wtk/TextArea.java src/org/apache/pivot/wtk/skin/TextAreaSkin.java src/org/apache/pivot/wtk/text/Element.java test/org/apache/pivot/wtk/text/test/TextAreaTest.java

Author: gbrown
Date: Tue Oct 27 21:28:17 2009
New Revision: 830348

URL: http://svn.apache.org/viewvc?rev=830348&view=rev
Log:
TextArea fixes.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/text/test/TextAreaTest.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=830348&r1=830347&r2=830348&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Tue Oct 27 21:28:17 2009
@@ -544,6 +544,8 @@
         }
 
         if (selectionLength > 0) {
+            // TODO Need to merge paragraphs here if we delete the terminator character;
+            // see below
             document.removeRange(selectionStart, selectionLength);
         } else {
             int offset = selectionStart;
@@ -580,6 +582,14 @@
                 }
             }
         }
+
+        // Ensure that the document remains editable
+        if (document.getCharacterCount() == 0) {
+            document.add(new Paragraph(""));
+        }
+
+        // Clear the selection length
+        selectionLength = 0;
     }
 
     public void cut() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=830348&r1=830347&r2=830348&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Tue Oct 27 21:28:17 2009
@@ -2093,6 +2093,9 @@
 
     private void updateSelection() {
         TextArea textArea = (TextArea)getComponent();
+
+        // TODO If the document is empty, clear both the caret and the selection
+
         int selectionStart = textArea.getSelectionStart();
         int selectionLength = textArea.getSelectionLength();
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java?rev=830348&r1=830347&r2=830348&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java Tue Oct 27 21:28:17 2009
@@ -24,7 +24,6 @@
 import org.apache.pivot.util.ImmutableIterator;
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Abstract base class for elements.
  * <p>
@@ -190,13 +189,21 @@
             if (start == end) {
                 // The range is entirely contained by one child node
                 Node node = get(start);
-                Node segment = node.removeRange(offset - node.getOffset(), characterCount);
-                element.add(segment);
+                int nodeOffset = node.getOffset();
+                int nodeCharacterCount = node.getCharacterCount();
 
-                // If the node's character count is now zero, remove it
-                if (node.getCharacterCount() == 0) {
+                Node segment;
+                if (offset == nodeOffset
+                    && characterCount == nodeCharacterCount) {
+                    // Remove the entire node
+                    segment = node;
                     remove(start, 1);
+                } else {
+                    // Remove a segment of the node
+                    segment = node.removeRange(offset - node.getOffset(), characterCount);
                 }
+
+                element.add(segment);
             } else {
                 // The range spans multiple child nodes
                 Node startNode = get(start);

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/text/test/TextAreaTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/text/test/TextAreaTest.java?rev=830348&r1=830347&r2=830348&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/text/test/TextAreaTest.java (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/text/test/TextAreaTest.java Tue Oct 27 21:28:17 2009
@@ -26,6 +26,7 @@
 import org.apache.pivot.wtk.Frame;
 import org.apache.pivot.wtk.Label;
 import org.apache.pivot.wtk.TextArea;
+import org.apache.pivot.wtk.TextAreaCharacterListener;
 import org.apache.pivot.wtk.TextAreaSelectionListener;
 import org.apache.pivot.wtk.TreeView;
 import org.apache.pivot.wtk.TreeViewSelectionListener;
@@ -84,8 +85,19 @@
             @Override
             public void selectionChanged(TextArea textArea,
                 int previousSelectionStart, int previousSelectionLength) {
-                selectionStartLabel.setText(Integer.toString(textArea.getSelectionStart()));
-                selectionLengthLabel.setText(Integer.toString(textArea.getSelectionLength()));
+                updateSelection();
+            }
+        });
+
+        textArea.getTextAreaCharacterListeners().add(new TextAreaCharacterListener() {
+            @Override
+            public void charactersRemoved(TextArea textArea, int index, int count) {
+                updateSelection();
+            }
+
+            @Override
+            public void charactersInserted(TextArea textArea, int index, int count) {
+                updateSelection();
             }
         });
 
@@ -152,6 +164,11 @@
     public void resume() {
     }
 
+    private void updateSelection() {
+        selectionStartLabel.setText(Integer.toString(textArea.getSelectionStart()));
+        selectionLengthLabel.setText(Integer.toString(textArea.getSelectionLength()));
+    }
+
     private void updateSelectedNodeData() {
         if (selectedNode == null) {
             offsetLabel.setText(null);