/** * Selects from the start offset to the end offset. This is the general selection method used by * all other selecting methods. The caret position will be start if start < end, and end if end * > start. * * @param start The start offset * @param end The end offset */ public void select(int start, int end) { int newStart, newEnd; boolean newBias; if (start <= end) { newStart = start; newEnd = end; newBias = false; } else { newStart = end; newEnd = start; newBias = true; } if (newStart < 0 || newEnd > getDocumentLength()) { throw new IllegalArgumentException("Bounds out of" + " range: " + newStart + "," + newEnd); } // If the new position is the same as the old, we don't // do all this crap, however we still do the stuff at // the end (clearing magic position, scrolling) if (newStart != selectionStart || newEnd != selectionEnd || newBias != biasLeft) { int newStartLine = getLineOfOffset(newStart); int newEndLine = getLineOfOffset(newEnd); if (painter.isBracketHighlightEnabled()) { if (bracketLine != -1) painter.invalidateLine(bracketLine); updateBracketHighlight(end); if (bracketLine != -1) painter.invalidateLine(bracketLine); } painter.invalidateLineRange(selectionStartLine, selectionEndLine); painter.invalidateLineRange(newStartLine, newEndLine); document.addUndoableEdit(new CaretUndo(selectionStart, selectionEnd)); selectionStart = newStart; selectionEnd = newEnd; selectionStartLine = newStartLine; selectionEndLine = newEndLine; biasLeft = newBias; fireCaretEvent(); } // When the user is typing, etc, we don't want the caret // to blink blink = true; caretTimer.restart(); // Disable rectangle select if selection start = selection end if (selectionStart == selectionEnd) rectSelect = false; // Clear the `magic' caret position used by up/down magicCaret = -1; scrollToCaret(); }