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/09/10 20:52:35 UTC
svn commit: r995926 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk:
Platform.java skin/TextAreaSkin2.java
Author: gbrown
Date: Fri Sep 10 18:52:35 2010
New Revision: 995926
URL: http://svn.apache.org/viewvc?rev=995926&view=rev
Log:
Improve word navigation in TextArea2.
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java?rev=995926&r1=995925&r2=995926&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java Fri Sep 10 18:52:35 2010
@@ -35,6 +35,7 @@ public class Platform {
private static final int DEFAULT_CURSOR_BLINK_RATE = 600;
private static final Modifier COMMAND_MODIFIER;
+ private static final Modifier WORD_NAVIGATION_MODIFIER;
private static final String KEYSTROKE_MODIFIER_SEPARATOR;
static {
@@ -42,9 +43,11 @@ public class Platform {
if (osName.startsWith("mac os x")) {
COMMAND_MODIFIER = Modifier.META;
+ WORD_NAVIGATION_MODIFIER = Modifier.ALT;
KEYSTROKE_MODIFIER_SEPARATOR = "";
} else {
COMMAND_MODIFIER = Modifier.CTRL;
+ WORD_NAVIGATION_MODIFIER = Modifier.CTRL;
KEYSTROKE_MODIFIER_SEPARATOR = "-";
}
@@ -125,12 +128,22 @@ public class Platform {
}
/**
- * Returns the system command modifier key. This is normally the CTRL or META key.
+ * Returns the system command modifier key.
*/
public static Modifier getCommandModifier() {
return COMMAND_MODIFIER;
}
+ /**
+ * Returns the word navigation modifier key.
+ */
+ public static Modifier getWordNavigationModifier() {
+ return WORD_NAVIGATION_MODIFIER;
+ }
+
+ /**
+ * Returns the keystroke modifier separator text.
+ */
public static String getKeyStrokeModifierSeparator() {
return KEYSTROKE_MODIFIER_SEPARATOR;
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java?rev=995926&r1=995925&r2=995926&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java Fri Sep 10 18:52:35 2010
@@ -781,6 +781,7 @@ public class TextAreaSkin2 extends Compo
TextArea2 textArea = (TextArea2)getComponent();
Keyboard.Modifier commandModifier = Platform.getCommandModifier();
+ Keyboard.Modifier wordNavigationModifier = Platform.getWordNavigationModifier();
if (keyCode == Keyboard.KeyCode.ENTER
&& textArea.isEditable()) {
@@ -807,41 +808,75 @@ public class TextAreaSkin2 extends Compo
}
consumed = true;
+ } else if (keyCode == Keyboard.KeyCode.HOME
+ || (keyCode == Keyboard.KeyCode.LEFT
+ && Keyboard.isPressed(commandModifier))) {
+ // TODO Move the caret to the beginning of the line
+ // (we need the row offset)
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ textArea.setSelection(0, textArea.getSelectionStart());
+ } else {
+ textArea.setSelection(0, 0);
+ }
+ scrollCharacterToVisible(0);
+
+ consumed = true;
+ } else if (keyCode == Keyboard.KeyCode.END
+ || (keyCode == Keyboard.KeyCode.RIGHT
+ && Keyboard.isPressed(commandModifier))) {
+ // TODO Move the caret to the end of the text
+ // (we need the row offset and length)
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ int selectionStart = textArea.getSelectionStart();
+ textArea.setSelection(selectionStart, textArea.getCharacterCount() - selectionStart);
+ } else {
+ textArea.setSelection(textArea.getCharacterCount() - 1, 0);
+ }
+ scrollCharacterToVisible(textArea.getCharacterCount() - 1);
+
+ consumed = true;
} else if (keyCode == Keyboard.KeyCode.LEFT) {
int selectionStart = textArea.getSelectionStart();
int selectionLength = textArea.getSelectionLength();
- // TODO Combine Control and Shift key behavior
- if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
- // Add the previous character to the selection
- if (selectionStart > 0) {
- selectionStart--;
- selectionLength++;
- }
- } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
- // Move the caret to the start of the next word to our left
+ if (Keyboard.isPressed(wordNavigationModifier)) {
+ // Move the caret to the start of the next word to the left
if (selectionStart > 0) {
// Skip over any space immediately to the left
- while (selectionStart > 0
- && Character.isWhitespace(textArea.getCharacterAt(selectionStart - 1))) {
- selectionStart--;
+ int index = selectionStart;
+ while (index > 0
+ && Character.isWhitespace(textArea.getCharacterAt(index - 1))) {
+ index--;
}
- // Skip over any word-letters to our left
- while (selectionStart > 0
- && !Character.isWhitespace(textArea.getCharacterAt(selectionStart - 1))) {
- selectionStart--;
+ // Skip over any word-letters to the left
+ while (index > 0
+ && !Character.isWhitespace(textArea.getCharacterAt(index - 1))) {
+ index--;
}
- selectionLength = 0;
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ selectionLength += selectionStart - index;
+ } else {
+ selectionLength = 0;
+ }
+
+ selectionStart = index;
+ }
+ } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ // Add the previous character to the selection
+ if (selectionStart > 0) {
+ selectionStart--;
+ selectionLength++;
}
} else {
- // Clear the selection and move the caret back by one character
+ // Move the caret back by one character
if (selectionLength == 0
&& selectionStart > 0) {
selectionStart--;
}
+ // Clear the selection
selectionLength = 0;
}
@@ -855,49 +890,54 @@ public class TextAreaSkin2 extends Compo
int selectionStart = textArea.getSelectionStart();
int selectionLength = textArea.getSelectionLength();
- // TODO Combine Control and Shift key behavior
- if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
- // Add the next character to the selection
- if (selectionStart + selectionLength < textArea.getCharacterCount()) {
- selectionLength++;
- }
-
- textArea.setSelection(selectionStart, selectionLength);
- scrollCharacterToVisible(selectionStart + selectionLength);
- } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
- // Move the caret to the start of the next word to our right
+ if (Keyboard.isPressed(wordNavigationModifier)) {
+ // Move the caret to the start of the next word to the right
if (selectionStart < textArea.getCharacterCount()) {
- // first, skip over any word-letters to our right
- while (selectionStart < textArea.getCharacterCount() - 1
- && !Character.isWhitespace(textArea.getCharacterAt(selectionStart))) {
- selectionStart++;
- }
- // then, skip over any space immediately to our right
- while (selectionStart < textArea.getCharacterCount() - 1
- && Character.isWhitespace(textArea.getCharacterAt(selectionStart))) {
- selectionStart++;
+ int index = selectionStart + selectionLength;
+
+ // Skip over any space immediately to the right
+ while (index < textArea.getCharacterCount()
+ && Character.isWhitespace(textArea.getCharacterAt(index))) {
+ index++;
}
- textArea.setSelection(selectionStart, 0);
- scrollCharacterToVisible(selectionStart);
+ // Skip over any word-letters to the right
+ while (index < textArea.getCharacterCount()
+ && !Character.isWhitespace(textArea.getCharacterAt(index))) {
+ index++;
+ }
- caretX = caret.x;
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ selectionLength = index - selectionStart;
+ } else {
+ selectionStart = index;
+ selectionLength = 0;
+ }
}
- } else {
- // Clear the selection and move the caret forward by one
- // character
- if (selectionLength > 0) {
- selectionStart += selectionLength - 1;
+ } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ // Add the next character to the selection
+ if (selectionStart + selectionLength < textArea.getCharacterCount()) {
+ selectionLength++;
}
-
- if (selectionStart < textArea.getCharacterCount()) {
+ } else {
+ // Move the caret forward by one character
+ if (selectionLength == 0) {
selectionStart++;
+ } else {
+ selectionStart += selectionLength;
}
- textArea.setSelection(selectionStart, 0);
- scrollCharacterToVisible(selectionStart);
+ // Clear the selection
+ selectionLength = 0;
+ }
+
+ textArea.setSelection(selectionStart, selectionLength);
+ scrollCharacterToVisible(selectionStart + selectionLength);
- caretX = caret.x;
+ caretX = caret.x;
+
+ if (selection != null) {
+ caretX += selection.getBounds2D().getWidth();
}
consumed = true;
@@ -997,27 +1037,6 @@ public class TextAreaSkin2 extends Compo
consumed = true;
}
- } else if (keyCode == Keyboard.KeyCode.HOME) {
- // Move the caret to the beginning of the text
- if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
- textArea.setSelection(0, textArea.getSelectionStart());
- } else {
- textArea.setSelection(0, 0);
- }
- scrollCharacterToVisible(0);
-
- consumed = true;
- } else if (keyCode == Keyboard.KeyCode.END) {
- // Move the caret to the end of the text
- if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
- int selectionStart = textArea.getSelectionStart();
- textArea.setSelection(selectionStart, textArea.getCharacterCount() - selectionStart);
- } else {
- textArea.setSelection(textArea.getCharacterCount() - 1, 0);
- }
- scrollCharacterToVisible(textArea.getCharacterCount() - 1);
-
- consumed = true;
} else {
consumed = super.keyPressed(component, keyCode, keyLocation);
}