if (index != -1) {
selectionLength = selectionStart + selectionLength - index;
}
} else {
// reduce downward size
Bounds trailingSelectionBounds = getCharacterBounds(selectionStart + selectionLength - 1);
int x = trailingSelectionBounds.x + trailingSelectionBounds.width;
index = getNextInsertionPoint(x, selectionStart + selectionLength - 1, TextArea.ScrollDirection.UP);
if (index != -1) {
if (index < anchor) {
selectionLength = anchor - index;
} else {
selectionLength = index - selectionStart;
index = selectionStart;
}
}
}
}
} else {
index = getNextInsertionPoint(caretX, selectionStart, TextArea.ScrollDirection.UP);
if (index != -1) {
selectionLength = 0;
}
anchor = -1;
}
if (index != -1) {
textArea.setSelection(index, selectionLength);
scrollCharacterToVisible(index);
caretX = caret.x;
}
consumed = true;
} else if (keyCode == Keyboard.KeyCode.DOWN) {
int selectionStart = textArea.getSelectionStart();
int selectionLength = textArea.getSelectionLength();
if (shiftPressed) {
int from;
int x;
int index;
if (anchor == -1) {
anchor = selectionStart;
index = getNextInsertionPoint(caretX, selectionStart, TextArea.ScrollDirection.DOWN);
if (index != -1) {
selectionLength = index - selectionStart;
}
} else {
if (selectionStart < anchor) {
// Reducing upward size
// Get next insertion point from leading selection character
from = selectionStart;
x = caretX;
index = getNextInsertionPoint(x, from, TextArea.ScrollDirection.DOWN);
if (index != -1) {
if (index < anchor) {
selectionStart = index;
selectionLength = anchor - index;
} else {
selectionStart = anchor;
selectionLength = index - anchor;
}
textArea.setSelection(selectionStart, selectionLength);
scrollCharacterToVisible(selectionStart);
}
} else {
// Increasing downward size
// Get next insertion point from right edge of trailing selection
// character
from = selectionStart + selectionLength - 1;
Bounds trailingSelectionBounds = getCharacterBounds(from);
x = trailingSelectionBounds.x + trailingSelectionBounds.width;
index = getNextInsertionPoint(x, from, TextArea.ScrollDirection.DOWN);
if (index != -1) {