public class InjectedCaret extends java.lang.Object implements Caret
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.
|
void |
dispose()
Usually not invoked directly, see class javadoc.
|
CaretModel |
getCaretModel()
Returns an instance of CaretModel, current caret is associated with.
|
Caret |
getDelegate() |
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() |
<T> T |
getUserData(Key<T> key) |
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
Caret.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.
|
<T> void |
putUserData(Key<T> key,
T value)
Add a new user data value to this object.
|
<T> T |
putUserDataIfAbsent(Key<T> key,
T value) |
void |
removeSelection()
Removes the selection in the editor.
|
<T> boolean |
replace(Key<T> key,
T oldValue,
T newValue)
Replaces (atomically) old value in the map with the new one
|
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.
|
public Editor getEditor()
Caret
public CaretModel getCaretModel()
Caret
getCaretModel
in interface Caret
public Caret getDelegate()
public boolean isValid()
Caret
isValid
in interface Caret
CaretModel.addCaret(VisualPosition)
,
CaretModel.removeCaret(Caret)
public void moveCaretRelatively(int columnShift, int lineShift, boolean withSelection, boolean scrollToCaret)
Caret
moveCaretRelatively
in interface Caret
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.public void moveToLogicalPosition(LogicalPosition pos)
Caret
moveToLogicalPosition
in interface Caret
pos
- the position to move to.public void moveToVisualPosition(VisualPosition pos)
Caret
moveToVisualPosition
in interface Caret
pos
- the position to move to.public void moveToOffset(int offset)
Caret
Caret.moveToOffset(int, boolean)
with 'false'
as a second argument.moveToOffset
in interface Caret
offset
- the offset to move topublic void moveToOffset(int offset, boolean locateBeforeSoftWrap)
Caret
moveToOffset
in interface Caret
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 offsetpublic boolean isUpToDate()
Caret
isUpToDate
in interface Caret
true
if caret position is up-to-date for now; false
otherwisepublic LogicalPosition getLogicalPosition()
Caret
getLogicalPosition
in interface Caret
public VisualPosition getVisualPosition()
Caret
getVisualPosition
in interface Caret
public int getOffset()
Caret
getOffset
in interface Caret
Caret.isValid()
public int getVisualLineStart()
getVisualLineStart
in interface Caret
public int getVisualLineEnd()
getVisualLineEnd
in interface Caret
public int getSelectionStart()
Caret
getSelectionStart
in interface Caret
public VisualPosition getSelectionStartPosition()
getSelectionStartPosition
in interface Caret
public int getSelectionEnd()
Caret
getSelectionEnd
in interface Caret
public VisualPosition getSelectionEndPosition()
getSelectionEndPosition
in interface Caret
public java.lang.String getSelectedText()
Caret
getSelectedText
in interface Caret
public int getLeadSelectionOffset()
Caret
getLeadSelectionOffset
in interface Caret
public VisualPosition getLeadSelectionPosition()
getLeadSelectionPosition
in interface Caret
public boolean hasSelection()
Caret
hasSelection
in interface Caret
public void setSelection(int startOffset, int endOffset)
Caret
System selection will be updated, if such feature is supported by current editor.
setSelection
in interface Caret
startOffset
- the start offset of the text range to select.endOffset
- the end offset of the text range to select.public void setSelection(int startOffset, int endOffset, boolean updateSystemSelection)
Caret
setSelection
in interface Caret
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)public void setSelection(int startOffset, VisualPosition endPosition, int endOffset)
Caret
System selection will be updated, if such feature is supported by current editor.
setSelection
in interface Caret
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 offsetpublic void setSelection(VisualPosition startPosition, int startOffset, VisualPosition endPosition, int endOffset)
Caret
System selection will be updated, if such feature is supported by current editor.
setSelection
in interface Caret
startPosition
- start visual position of the text range to select (null
argument means that
no specific visual position should be used)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 offsetpublic void setSelection(VisualPosition startPosition, int startOffset, VisualPosition endPosition, int endOffset, boolean updateSystemSelection)
Caret
setSelection
in interface Caret
startPosition
- start visual position of the text range to select (null
argument means that
no specific visual position should be used)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 offsetupdateSystemSelection
- whether system selection should be updated (might not have any effect if current editor doesn't support such a feature)public void removeSelection()
Caret
removeSelection
in interface Caret
public void selectLineAtCaret()
Caret
selectLineAtCaret
in interface Caret
public void selectWordAtCaret(boolean honorCamelWordsSettings)
Caret
selectWordAtCaret
in interface Caret
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.public Caret clone(boolean above)
Caret
clone
in interface Caret
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.public void dispose()
Disposable
dispose
in interface Disposable
public <T> T putUserDataIfAbsent(Key<T> key, T value)
putUserDataIfAbsent
in interface UserDataHolderEx
public <T> boolean replace(Key<T> key, T oldValue, T newValue)
UserDataHolderEx
replace
in interface UserDataHolderEx
ConcurrentMap.replace(Object, Object, Object)
public <T> T getUserData(Key<T> key)
getUserData
in interface UserDataHolder
public <T> void putUserData(Key<T> key, T value)
UserDataHolder
putUserData
in interface UserDataHolder
public boolean isAtRtlLocation()
Caret
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.isAtRtlLocation
in interface Caret
public boolean isAtBidiRunBoundary()
Caret
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
).isAtBidiRunBoundary
in interface Caret
public CaretVisualAttributes getVisualAttributes()
Caret
getVisualAttributes
in interface Caret
Caret.setVisualAttributes(CaretVisualAttributes)
public void setVisualAttributes(CaretVisualAttributes attributes)
Caret
setVisualAttributes
in interface Caret
Caret.getVisualAttributes()