int (JTextComponent t, int pos, int direction) { if (!isCurrentEventShiftDownEvent()) { if (direction == SwingConstants.WEST && t.getSelectionStart() < t.getSelectionEnd() && t.getSelectionEnd() == pos) { return t.getSelectionStart(); } if (direction == SwingConstants.EAST && t.getSelectionStart() < t.getSelectionEnd() && t.getSelectionStart() == pos) { return t.getSelectionEnd(); } } return -1; }