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/06 01:03:12 UTC
svn commit: r1817256 -
/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
Author: rwhitcomb
Date: Wed Dec 6 01:03:12 2017
New Revision: 1817256
URL: http://svn.apache.org/viewvc?rev=1817256&view=rev
Log:
PIVOT-891: Fix the left/right selection logic (I think it's all okay now,
with the possible exception of Shift-HOME and Shift-END and maybe word
navigation with Shift) in TextInput skin.
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=1817256&r1=1817255&r2=1817256&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 Wed Dec 6 01:03:12 2017
@@ -242,6 +242,8 @@ public class TerraTextInputSkin extends
private TextLayout textLayout = null;
private int anchor = -1;
+ private FocusTraversalDirection selectDirection = null;
+
private Rectangle caret = new Rectangle();
private Rectangle selection = null;
@@ -1060,8 +1062,10 @@ public class TerraTextInputSkin extends
// Select the range
if (offset > anchor) {
textInput.setSelection(anchor, offset - anchor);
+ selectDirection = FocusTraversalDirection.FORWARD;
} else {
textInput.setSelection(offset, anchor - offset);
+ selectDirection = FocusTraversalDirection.BACKWARD;
}
}
} else {
@@ -1349,6 +1353,7 @@ public class TerraTextInputSkin extends
consumed = true;
} else if (keyCode == Keyboard.KeyCode.LEFT) {
if (Keyboard.isPressed(wordNavigationModifier)) {
+ selectDirection = null;
// Move the caret to the start of the next word to the left
if (start > 0) {
// Skip over any space immediately to the left
@@ -1365,6 +1370,7 @@ public class TerraTextInputSkin extends
if (isShiftPressed) {
length += start - index;
+ selectDirection = FocusTraversalDirection.BACKWARD;
} else {
length = 0;
}
@@ -1372,12 +1378,44 @@ public class TerraTextInputSkin extends
start = index;
}
} else if (isShiftPressed) {
- // Add the previous character to the selection
- if (start > 0) {
- start--;
- length++;
+ // If the previous direction was BACKWARD, then increase the selection
+ // else decrease the selection back to the anchor.
+ if (selectDirection != null) {
+ switch (selectDirection) {
+ case FORWARD:
+ if (length == 0) {
+ if (start > 0) {
+ start--;
+ length++;
+ selectDirection = FocusTraversalDirection.BACKWARD;
+ }
+ } else {
+ if (--length == 0) {
+ if (start > 0) {
+ start--;
+ length++;
+ selectDirection = FocusTraversalDirection.BACKWARD;
+ }
+ }
+ }
+ break;
+ case BACKWARD:
+ if (start > 0) {
+ start--;
+ length++;
+ }
+ break;
+ }
+ } else {
+ // Add one to the selection
+ if (start > 0) {
+ start--;
+ length++;
+ selectDirection = FocusTraversalDirection.BACKWARD;
+ }
}
} else {
+ selectDirection = null;
// Move the caret back by one character
if (length == 0 && start > 0) {
start--;
@@ -1395,6 +1433,7 @@ public class TerraTextInputSkin extends
}
} else if (keyCode == Keyboard.KeyCode.RIGHT) {
if (Keyboard.isPressed(wordNavigationModifier)) {
+ selectDirection = null;
// Move the caret to the start of the next word to the right
if (start < textInput.getCharacterCount()) {
int index = start + length;
@@ -1413,15 +1452,40 @@ public class TerraTextInputSkin extends
if (isShiftPressed) {
length = index - start;
+ selectDirection = FocusTraversalDirection.FORWARD;
} else {
start = index;
length = 0;
}
}
} else if (isShiftPressed) {
- // Add the next character to the selection
- length++;
+ // If the previous direction was FORWARD, then increase the selection
+ // else decrease the selection back to the anchor.
+ if (selectDirection != null) {
+ switch (selectDirection) {
+ case FORWARD:
+ length++;
+ break;
+ case BACKWARD:
+ if (length == 0) {
+ length++;
+ selectDirection = FocusTraversalDirection.FORWARD;
+ } else {
+ start++;
+ if (--length == 0) {
+ length++;
+ selectDirection = FocusTraversalDirection.FORWARD;
+ }
+ }
+ break;
+ }
+ } else {
+ // Add the next character to the selection
+ length++;
+ selectDirection = FocusTraversalDirection.FORWARD;
+ }
} else {
+ selectDirection = null;
// Move the caret forward by one character
if (length == 0) {
start++;