Author: rwhitcomb
Date: Mon Feb 12 00:17:13 2018
New Revision: 1823914

URL: http://svn.apache.org/viewvc?rev=1823914&view=rev
Log:
PIVOT-891:  Further updates to TerraTextInputSkin to get the scrolling
correct when first doing mouse scrolling, then Shift-Arrow to reduce
the selection.  Requires thinking about where the movement is occurring
and put that location as visible.
Add a callback to TextInputs.java to put the focus on the control once
the window is fully open and visible (use a lambda function for the
callback).

Modified:
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/TextInputs.java
    
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java

Modified: 
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/TextInputs.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/TextInputs.java?rev=1823914&r1=1823913&r2=1823914&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/TextInputs.java 
(original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text/TextInputs.java 
Mon Feb 12 00:17:13 2018
@@ -22,6 +22,7 @@ import org.apache.pivot.beans.Bindable;
 import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.util.Resources;
+import org.apache.pivot.wtk.ApplicationContext;
 import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.TextInput;
 import org.apache.pivot.wtk.TextInputContentListener;
@@ -128,6 +129,6 @@ public class TextInputs extends Window i
     @Override
     public void open(Display display, Window owner) {
         super.open(display, owner);
-        stateTextInput.requestFocus();
+        ApplicationContext.queueCallback( () -> stateTextInput.requestFocus() 
);
     }
 }

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=1823914&r1=1823913&r2=1823914&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
 Mon Feb 12 00:17:13 2018
@@ -1080,6 +1080,7 @@ public class TerraTextInputSkin extends
                 if (scheduledScrollSelectionCallback == null) {
                     scrollDirection = (x < 0) ? 
FocusTraversalDirection.BACKWARD
                         : FocusTraversalDirection.FORWARD;
+                    selectDirection = (x < 0) ? SelectDirection.LEFT : 
SelectDirection.RIGHT;
 
                     // Run the callback once now to scroll the selection 
immediately
                     scheduledScrollSelectionCallback = 
ApplicationContext.runAndScheduleRecurringCallback(
@@ -1090,6 +1091,7 @@ public class TerraTextInputSkin extends
             if (Mouse.isPressed(Mouse.Button.LEFT) && Mouse.getCapturer() == 
null && anchor != -1) {
                 // Capture the mouse so we can select text
                 Mouse.capture(component);
+                selectDirection = null;
             }
         }
 
@@ -1119,6 +1121,7 @@ public class TerraTextInputSkin extends
                 } else {
                     // Move the caret to the insertion point
                     textInput.setSelection(anchor, 0);
+                    selectDirection = null;
                     consumed = true;
                 }
             }
@@ -1161,6 +1164,7 @@ public class TerraTextInputSkin extends
             } else if (count == 3) {
                 textInput.selectAll();
             }
+            selectDirection = null;
         }
 
         return super.mouseClick(component, button, x, y, count);
@@ -1320,6 +1324,9 @@ public class TerraTextInputSkin extends
 
             consumed = true;
         } else if (keyCode == Keyboard.KeyCode.LEFT) {
+            // Sometimes while selecting we need to make the opposite end 
visible
+            SelectDirection visiblePosition = SelectDirection.LEFT;
+
             if (Keyboard.isPressed(wordNavigationModifier)) {
                 int wordStart = (selectDirection == SelectDirection.RIGHT) ? 
start + length : start;
                 // Find the start of the next word to the left
@@ -1331,6 +1338,7 @@ public class TerraTextInputSkin extends
                             // We've just reduced the previous right 
selection, so leave the anchor alone
                             length = wordStart - start;
                             wordStart = start;
+                            visiblePosition = selectDirection;
                         } else {
                             if (selectDirection == SelectDirection.RIGHT) {
                                 // We've "crossed over" the start, so reverse 
direction
@@ -1373,6 +1381,8 @@ public class TerraTextInputSkin extends
                                         length++;
                                         selectDirection = SelectDirection.LEFT;
                                     }
+                                } else {
+                                    visiblePosition = selectDirection;
                                 }
                             }
                             break;
@@ -1398,11 +1408,21 @@ public class TerraTextInputSkin extends
 
             if (start >= 0) {
                 textInput.setSelection(start, length);
-                scrollCharacterToVisible(start);
+                switch (visiblePosition) {
+                    case LEFT:
+                        scrollCharacterToVisible(start);
+                        break;
+                    case RIGHT:
+                        scrollCharacterToVisible(start + length);
+                        break;
+                }
 
                 consumed = true;
             }
         } else if (keyCode == Keyboard.KeyCode.RIGHT) {
+            // Sometimes while selecting we need to make the opposite end 
visible
+            SelectDirection visiblePosition = SelectDirection.RIGHT;
+
             if (Keyboard.isPressed(wordNavigationModifier)) {
                 int wordStart = (selectDirection == SelectDirection.LEFT) ? 
start : start + length;
                 // Find the start of the next word to the right
@@ -1414,6 +1434,7 @@ public class TerraTextInputSkin extends
                             // We've just reduced the previous left selection, 
so leave the anchor alone
                             length -= wordStart - start;
                             start = wordStart;
+                            visiblePosition = selectDirection;
                         } else {
                             if (selectDirection == SelectDirection.LEFT) {
                                 // We've "crossed over" the start, so reverse 
direction
@@ -1448,6 +1469,8 @@ public class TerraTextInputSkin extends
                                 if (--length == 0) {
                                     length++;
                                     selectDirection = SelectDirection.RIGHT;
+                                } else {
+                                    visiblePosition = selectDirection;
                                 }
                             }
                             break;
@@ -1472,7 +1495,14 @@ public class TerraTextInputSkin extends
 
             if (start + length <= textInput.getCharacterCount()) {
                 textInput.setSelection(start, length);
-                scrollCharacterToVisible(start + length);
+                switch (visiblePosition) {
+                    case LEFT:
+                        scrollCharacterToVisible(start);
+                        break;
+                    case RIGHT:
+                        scrollCharacterToVisible(start + length);
+                        break;
+                }
 
                 consumed = true;
             }


Reply via email to