You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/12/08 00:32:42 UTC

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

Author: rwhitcomb
Date: Fri Dec  8 00:32:42 2017
New Revision: 1817444

URL: http://svn.apache.org/viewvc?rev=1817444&view=rev
Log:
PIVOT-891:  Add a new "SelectDirection" enum in preparation for updating
the selection logic in TextArea and TextPane (which have four directions
for selecting).  Then update TextInput to use this enum also (instead of
the FocusTraversalDirection, which just has FORWARD and BACKWARD).

Note: I think there is a small bug in TextInput logic when you start at
the end of the text, go left for a bit, then go right until the end, then
left again -- the last position ends up being the last char selected
instead of the caret at the end of text again.  Something like that...

Added:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/SelectDirection.java
Modified:
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.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=1817444&r1=1817443&r2=1817444&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 Dec  8 00:32:42 2017
@@ -54,6 +54,7 @@ import org.apache.pivot.wtk.Keyboard.Mod
 import org.apache.pivot.wtk.Mouse;
 import org.apache.pivot.wtk.Orientation;
 import org.apache.pivot.wtk.Platform;
+import org.apache.pivot.wtk.SelectDirection;
 import org.apache.pivot.wtk.TextInput;
 import org.apache.pivot.wtk.TextInputContentListener;
 import org.apache.pivot.wtk.TextInputListener;
@@ -242,7 +243,7 @@ public class TerraTextInputSkin extends
     private TextLayout textLayout = null;
 
     private int anchor = -1;
-    private FocusTraversalDirection selectDirection = null;
+    private SelectDirection selectDirection = null;
 
     private Rectangle caret = new Rectangle();
     private Rectangle selection = null;
@@ -1062,10 +1063,10 @@ public class TerraTextInputSkin extends
                     // Select the range
                     if (offset > anchor) {
                         textInput.setSelection(anchor, offset - anchor);
-                        selectDirection = FocusTraversalDirection.FORWARD;
+                        selectDirection = SelectDirection.RIGHT;
                     } else {
                         textInput.setSelection(offset, anchor - offset);
-                        selectDirection = FocusTraversalDirection.BACKWARD;
+                        selectDirection = SelectDirection.LEFT;
                     }
                 }
             } else {
@@ -1370,7 +1371,7 @@ public class TerraTextInputSkin extends
 
                     if (isShiftPressed) {
                         length += start - index;
-                        selectDirection = FocusTraversalDirection.BACKWARD;
+                        selectDirection = SelectDirection.LEFT;
                     } else {
                         length = 0;
                     }
@@ -1378,40 +1379,40 @@ public class TerraTextInputSkin extends
                     start = index;
                 }
             } else if (isShiftPressed) {
-                // If the previous direction was BACKWARD, then increase the selection
+                // If the previous direction was LEFT, then increase the selection
                 // else decrease the selection back to the anchor.
                 if (selectDirection != null) {
                     switch (selectDirection) {
-                        case FORWARD:
+                        case LEFT:
+                            if (start > 0) {
+                                start--;
+                                length++;
+                            }
+                            break;
+                        case RIGHT:
                             if (length == 0) {
                                 if (start > 0) {
                                     start--;
                                     length++;
-                                    selectDirection = FocusTraversalDirection.BACKWARD;
+                                    selectDirection = SelectDirection.LEFT;
                                 }
                             } else {
                                 if (--length == 0) {
                                     if (start > 0) {
                                         start--;
                                          length++;
-                                        selectDirection = FocusTraversalDirection.BACKWARD;
+                                        selectDirection = SelectDirection.LEFT;
                                     }
                                 }
                             }
                             break;
-                        case BACKWARD:
-                            if (start > 0) {
-                                start--;
-                                length++;
-                            }
-                            break;
                     }
                 } else {
                     // Add one to the selection
                     if (start > 0) {
                         start--;
                         length++;
-                        selectDirection = FocusTraversalDirection.BACKWARD;
+                        selectDirection = SelectDirection.LEFT;
                     }
                 }
             } else {
@@ -1452,29 +1453,29 @@ public class TerraTextInputSkin extends
 
                     if (isShiftPressed) {
                         length = index - start;
-                        selectDirection = FocusTraversalDirection.FORWARD;
+                        selectDirection = SelectDirection.RIGHT;
                     } else {
                         start = index;
                         length = 0;
                     }
                 }
             } else if (isShiftPressed) {
-                // If the previous direction was FORWARD, then increase the selection
+                // If the previous direction was RIGHT, then increase the selection
                 // else decrease the selection back to the anchor.
                 if (selectDirection != null) {
                     switch (selectDirection) {
-                        case FORWARD:
+                        case RIGHT:
                             length++;
                             break;
-                        case BACKWARD:
+                        case LEFT:
                             if (length == 0) {
                                 length++;
-                                selectDirection = FocusTraversalDirection.FORWARD;
+                                selectDirection = SelectDirection.RIGHT;
                             } else {
                                 start++;
                                 if (--length == 0) {
                                     length++;
-                                    selectDirection = FocusTraversalDirection.FORWARD;
+                                    selectDirection = SelectDirection.RIGHT;
                                 }
                             }
                             break;
@@ -1482,7 +1483,7 @@ public class TerraTextInputSkin extends
                 } else {
                     // Add the next character to the selection
                     length++;
-                    selectDirection = FocusTraversalDirection.FORWARD;
+                    selectDirection = SelectDirection.RIGHT;
                 }
             } else {
                 selectDirection = null;

Added: pivot/trunk/wtk/src/org/apache/pivot/wtk/SelectDirection.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/SelectDirection.java?rev=1817444&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/SelectDirection.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/SelectDirection.java Fri Dec  8 00:32:42 2017
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk;
+
+/**
+ * Enumeration of the possible directions we can select in.  In other words,
+ * which arrow key was first used to initiate selecting?
+ * <p> Used by {@link TextArea} and {@link TextPane} for two-dimensional
+ * selection logic.  {@link TextInput} uses just forward/backward and not
+ * this enum.
+ */
+public enum SelectDirection {
+    LEFT,
+    RIGHT,
+    UP,
+    DOWN
+}