}
else {
if (!fAnchor.equals(fStart))
fAnchor.assign(fLimit);
TextOffset liveEnd = (fStart.equals(fAnchor)) ? fLimit : fStart;
TextOffset newPos = new TextOffset();
// if the control key is down, the left and right arrow keys move by whole
// word in the appropriate direction (we use a line break object so that we're
// not treating spaces and punctuation as words)
if (e.isControlDown() && (key == KeyEvent.VK_LEFT || key == KeyEvent.VK_RIGHT)) {
fUpDownAnchor = null;
fBoundaries = BreakIterator.getLineInstance();
fBoundaries.setText(fText.createCharacterIterator());
newPos.assign(liveEnd);
if (key == KeyEvent.VK_RIGHT)
advanceToNextBoundary(newPos);
else
advanceToPreviousBoundary(newPos, true);
}
// if we get down to here, this is a plain-vanilla insertion-point move,
// or the shift key is down and we're extending or shortening the selection
else {
// fUpDownAnchor is used to keep track of the horizontal position
// across a run of up or down arrow keys (this prevents accumulated
// error from destroying our horizontal position)
if (key == KeyEvent.VK_LEFT || key == KeyEvent.VK_RIGHT)
fUpDownAnchor = null;
else {
if (fUpDownAnchor == null) {
fUpDownAnchor = new TextOffset(liveEnd);
}
}
short direction = MFormatter.eRight; // just to have a default...
switch (key) {
case KeyEvent.VK_UP: direction = MFormatter.eUp; break;
case KeyEvent.VK_DOWN: direction = MFormatter.eDown; break;
case KeyEvent.VK_LEFT: direction = MFormatter.eLeft; break;
case KeyEvent.VK_RIGHT: direction = MFormatter.eRight; break;
}
// use the formatter to determine the actual effect of the arrow key
fTextComponent.findNewInsertionOffset(newPos, fUpDownAnchor, liveEnd, direction);
}
// if the shift key is down, the selection range is from the anchor point
// the site of the last insertion point or the beginning point of the last
// selection drag operation) to the newly-calculated position; if the
// shift key is down, the newly-calculated position is the insertion point position
if (!e.isShiftDown())
setSelRangeAndDraw(newPos, newPos, newPos);
else {
if (newPos.lessThan(fAnchor))
setSelRangeAndDraw(newPos, fAnchor, fAnchor);
else
setSelRangeAndDraw(fAnchor, newPos, fAnchor);
}
}