public interface Caret extends UserDataHolderEx, Disposable
Instances of this interface are supposed to be obtained from CaretModel
instance, and not created explicitly.
Disposable.Parent
Modifier and Type | Method and Description |
---|---|
Caret |
clone(boolean above)
Clones the current caret and positions the new one right above or below the current one.
|
CaretModel |
getCaretModel()
Returns an instance of CaretModel, current caret is associated with.
|
Editor |
getEditor()
Returns an instance of Editor, current caret belongs to.
|
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).
|
VisualPosition |
getLeadSelectionPosition() |
LogicalPosition |
getLogicalPosition()
Returns the logical position of the caret.
|
int |
getOffset()
Returns the offset of the caret in the document.
|
java.lang.String |
getSelectedText()
Returns the text selected in the editor.
|
int |
getSelectionEnd()
Returns the end offset in the document of the selected text range, or the caret
position if there is currently no selection.
|
VisualPosition |
getSelectionEndPosition() |
int |
getSelectionStart()
Returns the start offset in the document of the selected text range, or the caret
position if there is currently no selection.
|
VisualPosition |
getSelectionStartPosition() |
CaretVisualAttributes |
getVisualAttributes()
Returns visual attributes currently set for the caret.
|
int |
getVisualLineEnd() |
int |
getVisualLineStart() |
VisualPosition |
getVisualPosition()
Returns the visual position of the caret.
|
boolean |
hasSelection()
Checks if a range of text is currently selected.
|
boolean |
isAtBidiRunBoundary()
Returns
true if caret is located at a boundary between different runs of bidirectional text. |
boolean |
isAtRtlLocation()
Returns
true if caret is located in RTL text fragment. |
boolean |
isUpToDate()
Caret position may be updated on document change (e.g.
|
boolean |
isValid()
Tells whether this caret is valid, i.e.
|
void |
moveCaretRelatively(int columnShift,
int lineShift,
boolean withSelection,
boolean scrollToCaret)
Moves the caret by the specified number of lines and/or columns.
|
void |
moveToLogicalPosition(LogicalPosition pos)
Moves the caret to the specified logical position.
|
void |
moveToOffset(int offset)
Short hand for calling
moveToOffset(int, boolean) with 'false' as a second argument. |
void |
moveToOffset(int offset,
boolean locateBeforeSoftWrap)
Moves the caret to the specified offset in the document.
|
void |
moveToVisualPosition(VisualPosition pos)
Moves the caret to the specified visual position.
|
void |
removeSelection()
Removes the selection in the editor.
|
void |
selectLineAtCaret()
Selects the entire line of text at the caret position.
|
void |
selectWordAtCaret(boolean honorCamelWordsSettings)
Selects the entire word at the caret position, optionally using camel-case rules to
determine word boundaries.
|
void |
setSelection(int startOffset,
int endOffset)
Selects the specified range of text.
|
void |
setSelection(int startOffset,
int endOffset,
boolean updateSystemSelection)
Selects the specified range of text.
|
void |
setSelection(int startOffset,
VisualPosition endPosition,
int endOffset)
Selects target range providing information about visual boundary of selection end.
|
void |
setSelection(VisualPosition startPosition,
int startOffset,
VisualPosition endPosition,
int endOffset)
Selects target range based on its visual boundaries.
|
void |
setSelection(VisualPosition startPosition,
int startOffset,
VisualPosition endPosition,
int endOffset,
boolean updateSystemSelection)
Selects target range based on its visual boundaries.
|
void |
setVisualAttributes(CaretVisualAttributes attributes)
Sets caret's current visual attributes.
|
putUserDataIfAbsent, replace
getUserData, putUserData
dispose
Editor getEditor()
CaretModel getCaretModel()
boolean isValid()
void moveCaretRelatively(int columnShift, int lineShift, boolean withSelection, boolean scrollToCaret)
columnShift
- the number of columns to move the caret by.lineShift
- the number of lines to move the caret by.withSelection
- if true, the caret move should extend the selection in the document.scrollToCaret
- if true, the document should be scrolled so that the caret is visible after the move.void moveToLogicalPosition(LogicalPosition pos)
pos
- the position to move to.void moveToVisualPosition(VisualPosition pos)
pos
- the position to move to.void moveToOffset(int offset)
moveToOffset(int, boolean)
with 'false'
as a second argument.offset
- the offset to move tovoid moveToOffset(int offset, boolean locateBeforeSoftWrap)
offset
- the offset to move to.locateBeforeSoftWrap
- there is a possible case that there is a soft wrap at the given offset, hence, the same offset
corresponds to two different visual positions - just before soft wrap and just after soft wrap.
We may want to clearly indicate where to put the caret then. Given parameter allows to do that.
Note: it's ignored if there is no soft wrap at the given offsetboolean isUpToDate()
true
if caret position is up-to-date for now; false
otherwiseLogicalPosition getLogicalPosition()
VisualPosition getVisualPosition()
int getOffset()
isValid()
int getVisualLineStart()
int getVisualLineEnd()
int getSelectionStart()
VisualPosition getSelectionStartPosition()
int getSelectionEnd()
VisualPosition getSelectionEndPosition()
java.lang.String getSelectedText()
int getLeadSelectionOffset()
VisualPosition getLeadSelectionPosition()
boolean hasSelection()
void setSelection(int startOffset, int endOffset)
System selection will be updated, if such feature is supported by current editor.
startOffset
- the start offset of the text range to select.endOffset
- the end offset of the text range to select.void setSelection(int startOffset, int endOffset, boolean updateSystemSelection)
startOffset
- the start offset of the text range to select.endOffset
- the end offset of the text range to select.updateSystemSelection
- whether system selection should be updated (might not have any effect if current editor doesn't support such a feature)void setSelection(int startOffset, VisualPosition endPosition, int endOffset)
System selection will be updated, if such feature is supported by current editor.
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 offsetvoid setSelection(VisualPosition startPosition, int startOffset, VisualPosition endPosition, int endOffset)
System selection will be updated, if such feature is supported by current editor.
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 offsetvoid setSelection(VisualPosition startPosition, int startOffset, VisualPosition endPosition, int endOffset, boolean updateSystemSelection)
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 offsetupdateSystemSelection
- whether system selection should be updated (might not have any effect if current editor doesn't support such a feature)void removeSelection()
void selectLineAtCaret()
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.Caret clone(boolean above)
above
- if true
, new caret will be created at the previous line, if false
- on the next linenull
if the caret cannot be created because it already exists at the new location
or caret model doesn't support multiple carets.boolean isAtRtlLocation()
true
if caret is located in RTL text fragment. In that case visual column number is inversely related
to offset and logical column number in the vicinity of caret.boolean isAtBidiRunBoundary()
true
if caret is located at a boundary between different runs of bidirectional text.
This means that text fragments at different sides of the boundary are non-adjacent in logical order.
Caret can located at any side of the boundary,
exact location can be determined from directionality flags of caret's logical and visual position
(LogicalPosition.leansForward
and VisualPosition.leansRight
).CaretVisualAttributes getVisualAttributes()
void setVisualAttributes(CaretVisualAttributes attributes)
getVisualAttributes()