Author: noelgrandin
Date: Wed May 5 12:53:17 2010
New Revision: 941272
URL: http://svn.apache.org/viewvc?rev=941272&view=rev
Log:
PIVOT-371 Support word navigation in TextInput and TextArea
also fix OutOfBounds checks in TextArea#setSelection
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=941272&r1=941271&r2=941272&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Wed May 5 12:53:17
2010
@@ -688,12 +688,21 @@ public class TextArea extends Component
}
if (selectionLength < 0) {
- throw new IllegalArgumentException("selectionLength is negative.");
+ throw new IllegalArgumentException("selectionLength is negative,
selectionLength=" + selectionLength);
}
- if (selectionStart < 0
- || selectionStart + selectionLength >
document.getCharacterCount()) {
- throw new IndexOutOfBoundsException();
+ if (selectionStart < 0) {
+ throw new IndexOutOfBoundsException("selectionStart < 0,
selectionStart=" + selectionStart);
+ }
+
+ if (selectionStart >= document.getCharacterCount()) {
+ throw new IndexOutOfBoundsException("selectionStart=" +
selectionStart
+ + ", document.characterCount=" + document.getCharacterCount());
+ }
+
+ if (selectionStart + selectionLength > document.getCharacterCount()) {
+ throw new IndexOutOfBoundsException("selectionStart=" +
selectionStart + ", selectionLength=" + selectionLength
+ + ", document.characterCount=" + document.getCharacterCount());
}
int previousSelectionStart = this.selectionStart;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=941272&r1=941271&r2=941272&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Wed May 5
12:53:17 2010
@@ -2078,6 +2078,22 @@ public class TextAreaSkin extends Compon
selectionStart--;
selectionLength++;
}
+ } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
+ // Move the caret to the start of the next word to our left
+ if (selectionStart > 0) {
+ // first, skip over any space immediately to our left
+ while (selectionStart > 0
+ &&
Character.isWhitespace(document.getCharacterAt(selectionStart - 1))) {
+ selectionStart--;
+ }
+ // then, skip over any word-letters to our left
+ while (selectionStart > 0
+ &&
!Character.isWhitespace(document.getCharacterAt(selectionStart - 1))) {
+ selectionStart--;
+ }
+
+ selectionLength = 0;
+ }
} else {
// Clear the selection and move the caret back by one
// character
@@ -2107,6 +2123,25 @@ public class TextAreaSkin extends Compon
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 (selectionStart < document.getCharacterCount()) {
+ // first, skip over any word-letters to our right
+ while (selectionStart < document.getCharacterCount() -
1
+ &&
!Character.isWhitespace(document.getCharacterAt(selectionStart))) {
+ selectionStart++;
+ }
+ // then, skip over any space immediately to our right
+ while (selectionStart < document.getCharacterCount() -
1
+ &&
Character.isWhitespace(document.getCharacterAt(selectionStart))) {
+ selectionStart++;
+ }
+
+ textArea.setSelection(selectionStart, 0);
+ scrollCharacterToVisible(selectionStart);
+
+ caretX = caret.x;
+ }
} else {
// Clear the selection and move the caret forward by one
// character