public interface SelectionModel
CaretModel
now.
In editors supporting multiple carets, each caret has its own associated selection range. Unless mentioned explicitly, methods of this
interface operate on the current caret (see CaretModel.runForEachCaret(CaretAction)
), or 'primary' caret if current caret
is not defined.
Editor.getSelectionModel()
,
CaretModel
Modifier and Type | Method and Description |
---|---|
void |
addSelectionListener(SelectionListener listener)
Adds a listener for receiving information about selection changes.
|
default void |
addSelectionListener(SelectionListener listener,
Disposable parentDisposable)
Adds a listener for receiving information about selection changes, which is removed when the given disposable is disposed.
|
void |
copySelectionToClipboard()
Copies the currently selected text to the clipboard.
|
int [] |
getBlockSelectionEnds()
Returns an array of end offsets in the document for ranges selected in the document currently.
|
int [] |
getBlockSelectionStarts()
Returns an array of start offsets in the document for ranges selected in the document currently.
|
Editor |
getEditor() |
default int |
getLeadSelectionOffset()
Returns the offset from which the user started to extend the selection (the selection start
if the selection was extended in forward direction, or the selection end if it was
extended backward).
|
default VisualPosition |
getLeadSelectionPosition() |
default java.lang.String |
getSelectedText()
Returns the text selected in the editor.
|
default java.lang.String |
getSelectedText(boolean allCarets)
If
allCarets is true , returns the concatenation of selections for all carets, or null if there
are no selections. |
default int |
getSelectionEnd()
Returns the end offset in the document of the selected text range, or the caret
position if there is currently no selection.
|
default VisualPosition |
getSelectionEndPosition() |
default int |
getSelectionStart()
Returns the start offset in the document of the selected text range, or the caret
position if there is currently no selection.
|
default VisualPosition |
getSelectionStartPosition() |
TextAttributes |
getTextAttributes()
Returns visual representation of selection.
|
default boolean |
hasSelection()
Checks if a range of text is currently selected.
|
default boolean |
hasSelection(boolean anyCaret)
Checks if a range of text is currently selected.
|
default void |
removeSelection()
Removes the selection in the editor.
|
default void |
removeSelection(boolean allCarets)
Removes the selection in the editor.
|
void |
removeSelectionListener(SelectionListener listener)
Removes a listener for receiving information about selection changes.
|
default void |
selectLineAtCaret()
Selects the entire line of text at the caret position.
|
default void |
selectWordAtCaret(boolean honorCamelWordsSettings)
Selects the entire word at the caret position, optionally using camel-case rules to
determine word boundaries.
|
void |
setBlockSelection(LogicalPosition blockStart,
LogicalPosition blockEnd)
Creates a multi-caret selection for the rectangular block of text with specified start and end positions.
|
default void |
setSelection(int startOffset,
int endOffset)
Selects the specified range of text.
|
default void |
setSelection(int startOffset,
VisualPosition endPosition,
int endOffset)
Selects target range providing information about visual boundary of selection end.
|
default void |
setSelection(VisualPosition startPosition,
int startOffset,
VisualPosition endPosition,
int endOffset)
Selects target range based on its visual boundaries.
|
Editor getEditor()
default int getSelectionStart()
default VisualPosition getSelectionStartPosition()
default int getSelectionEnd()
default VisualPosition getSelectionEndPosition()
default java.lang.String getSelectedText()
null
if there is currently no selection.default java.lang.String getSelectedText(boolean allCarets)
allCarets
is true
, returns the concatenation of selections for all carets, or null
if there
are no selections. If allCarets
is false
, works just like getSelectedText()
.default int getLeadSelectionOffset()
default VisualPosition getLeadSelectionPosition()
default boolean hasSelection()
true
if a range of text is selected, false
otherwise.default boolean hasSelection(boolean anyCaret)
anyCaret
is true
, check all existing carets in
the document, and returns true
if any of them has selection, otherwise checks only the current caret.true
if a range of text is selected, false
otherwise.default void setSelection(int startOffset, int endOffset)
startOffset
- the start offset of the text range to select.endOffset
- the end offset of the text range to select.default void setSelection(int startOffset, VisualPosition endPosition, int endOffset)
startOffset
- start selection offsetendPosition
- end visual position of the text range to select (null
argument means that
no specific visual position should be used)endOffset
- end selection offsetdefault void setSelection(VisualPosition startPosition, int startOffset, VisualPosition endPosition, int endOffset)
startPosition
- start visual position of the text range to select (null
argument means that
no specific visual position should be used)endPosition
- end visual position of the text range to select (null
argument means that
no specific visual position should be used)startOffset
- start selection offsetendOffset
- end selection offsetdefault void removeSelection()
default void removeSelection(boolean allCarets)
allCarets
is true
, removes selections from all carets in the
editor, otherwise, does this just for the current caret.void addSelectionListener(SelectionListener listener)
listener
- the listener instance.default void addSelectionListener(SelectionListener listener, Disposable parentDisposable)
listener
- the listener instance.void removeSelectionListener(SelectionListener listener)
listener
- the listener instance.default void selectLineAtCaret()
default void selectWordAtCaret(boolean honorCamelWordsSettings)
honorCamelWordsSettings
- if true and "Use CamelHumps words" is enabled,
upper-case letters within the word are considered as
boundaries for the range of text to select.void copySelectionToClipboard()
void setBlockSelection(LogicalPosition blockStart, LogicalPosition blockEnd)
blockStart
- the start of the rectangle to select.blockEnd
- the end of the rectangle to select.setSelection(int, int)
int [] getBlockSelectionStarts()
int [] getBlockSelectionEnds()
TextAttributes getTextAttributes()