public class CaretModelImpl extends java.lang.Object implements CaretModel, PrioritizedDocumentListener, Disposable, Dumpable, InlayModel.Listener
Disposable.Parent
COMPARATOR
ARRAY_FACTORY, EMPTY_ARRAY
Constructor and Description |
---|
CaretModelImpl(EditorImpl editor) |
Modifier and Type | Method and Description |
---|---|
Caret |
addCaret(LogicalPosition pos,
boolean makePrimary)
Adds a new caret at the given position, and returns corresponding
Caret instance. |
Caret |
addCaret(VisualPosition pos,
boolean makePrimary)
Adds a new caret at the given position, and returns corresponding
Caret instance. |
void |
addCaretActionListener(CaretActionListener listener,
Disposable disposable)
Adds a listener which will be notified before and after all-caret operations are performed by
CaretModel.runForEachCaret(CaretAction) and
CaretModel.runForEachCaret(CaretAction, boolean) . |
void |
addCaretListener(CaretListener listener)
Adds a listener for receiving notifications about caret movement and caret addition/removal
|
void |
beforeDocumentChange(DocumentEvent e)
Called before the text of the document is changed.
|
void |
dispose()
Usually not invoked directly, see class javadoc.
|
void |
documentChanged(DocumentEvent e)
Called after the text of the document has been changed.
|
java.lang.String |
dumpState() |
java.util.List<Caret> |
getAllCarets()
Returns all carets currently existing in the document, ordered by their visual position in editor.
|
Caret |
getCaretAt(VisualPosition pos)
Returns a caret at the given position in the document, or
null , if there's no caret there. |
int |
getCaretCount()
Returns number of carets currently existing in the document
|
java.util.List<CaretState> |
getCaretsAndSelections()
Returns the current positions of all carets and their selections.
|
CaretImpl |
getCurrentCaret()
Returns current caret - the one, query and update methods in the model operate at the moment.
|
CaretImpl |
getPrimaryCaret()
Returns the 'primary' caret.
|
int |
getPriority() |
TextAttributes |
getTextAttributes()
Returns visual representation of caret (e.g.
|
boolean |
isIteratingOverCarets() |
void |
onAdded(Inlay inlay) |
void |
onBatchModeFinish(Editor editor) |
void |
onRemoved(Inlay inlay) |
void |
onUpdated(Inlay inlay,
int changeFlags) |
void |
reinitSettings() |
boolean |
removeCaret(Caret caret)
Removes a given caret if it's recognized by the model and is not the only existing caret in the document, returning
true . |
void |
removeCaretListener(CaretListener listener)
Removes a listener for receiving notifications about caret movement and caret addition/removal
|
void |
removeSecondaryCarets()
Removes all carets except the 'primary' one from the document.
|
void |
runBatchCaretOperation(java.lang.Runnable runnable)
Executes the given task, performing caret merging afterwards.
|
void |
runForEachCaret(CaretAction action)
|
void |
runForEachCaret(CaretAction action,
boolean reverseOrder)
Executes the given task for each existing caret.
|
void |
setCaretsAndSelections(java.util.List<? extends CaretState> caretStates)
Sets the number of carets, their positions and selection ranges according to the provided data.
|
void |
setCaretsAndSelections(java.util.List<? extends CaretState> caretStates,
boolean updateSystemSelection)
Sets the number of carets, their positions and selection ranges according to the provided data.
|
boolean |
supportsMultipleCarets()
Tells whether multiple coexisting carets are supported by this CaretModel instance.
|
void |
updateVisualPosition() |
void |
validateState() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addCaret, addCaretListener, getLogicalPosition, getOffset, getVisualLineEnd, getVisualLineStart, getVisualPosition, isUpToDate, moveCaretRelatively, moveToLogicalPosition, moveToOffset, moveToOffset, moveToVisualPosition
bulkUpdateFinished, bulkUpdateStarting
onBatchModeStart, onUpdated
public CaretModelImpl(EditorImpl editor)
public void documentChanged(DocumentEvent e)
DocumentListener
documentChanged
in interface DocumentListener
e
- the event containing the information about the change.public void beforeDocumentChange(DocumentEvent e)
DocumentListener
beforeDocumentChange
in interface DocumentListener
e
- the event containing the information about the change.public int getPriority()
getPriority
in interface PrioritizedDocumentListener
public void dispose()
Disposable
dispose
in interface Disposable
public void updateVisualPosition()
public void addCaretListener(CaretListener listener)
CaretModel
addCaretListener
in interface CaretModel
listener
- the listener instance.public void removeCaretListener(CaretListener listener)
CaretModel
removeCaretListener
in interface CaretModel
listener
- the listener instance.public TextAttributes getTextAttributes()
CaretModel
getTextAttributes
in interface CaretModel
public void reinitSettings()
public boolean supportsMultipleCarets()
CaretModel
supportsMultipleCarets
in interface CaretModel
public CaretImpl getCurrentCaret()
CaretModel
CaretModel.runForEachCaret(CaretAction)
method, or the 'primary' caret without that
context. Users CaretModel.runForEachCaret(CaretAction)
method should use caret parameter passed to
CaretAction.perform(Caret)
method instead of this method, as the definition of current caret (as
well as caret instance operated on by model methods) can potentially change.getCurrentCaret
in interface CaretModel
public CaretImpl getPrimaryCaret()
CaretModel
getPrimaryCaret
in interface CaretModel
public int getCaretCount()
CaretModel
getCaretCount
in interface CaretModel
public java.util.List<Caret> getAllCarets()
CaretModel
getAllCarets
in interface CaretModel
public Caret getCaretAt(VisualPosition pos)
CaretModel
null
, if there's no caret there.getCaretAt
in interface CaretModel
public Caret addCaret(VisualPosition pos, boolean makePrimary)
CaretModel
Caret
instance. Locations outside of possible values
for the given document are trimmed automatically.
Newly added caret will become a primary caret if and only if makePrimary
value is true
.
Does nothing if multiple carets are not supported, a caret already exists at specified location or selection of existing caret
includes the specified location, null
is returned in this case.addCaret
in interface CaretModel
public Caret addCaret(LogicalPosition pos, boolean makePrimary)
CaretModel
Caret
instance. Locations outside of possible values
for the given document are trimmed automatically.
Newly added caret will become a primary caret if and only if makePrimary
value is true
.
Does nothing if multiple carets are not supported, a caret already exists at specified location or selection of existing caret
includes the specified location, null
is returned in this case.addCaret
in interface CaretModel
public boolean removeCaret(Caret caret)
CaretModel
true
.
false
is returned if any of the above condition doesn't hold, and the removal cannot happen.removeCaret
in interface CaretModel
public void removeSecondaryCarets()
CaretModel
removeSecondaryCarets
in interface CaretModel
public void runForEachCaret(CaretAction action)
CaretModel
runForEachCaret
in interface CaretModel
public void runForEachCaret(CaretAction action, boolean reverseOrder)
CaretModel
Carets are iterated in position order (top-to-bottom) if reverseOrder
is false
, and in reverse order
if it's true
.
It's possible to call this method not from EDT (for read-only operations). Caret merging is not performed in this case, and no
notifications to CaretActionListener
-s are sent.
runForEachCaret
in interface CaretModel
public void addCaretActionListener(CaretActionListener listener, Disposable disposable)
CaretModel
CaretModel.runForEachCaret(CaretAction)
and
CaretModel.runForEachCaret(CaretAction, boolean)
. Listeners will be notified only if those methods are invoked from EDT (non-EDT
invocations are not allowed to change caret state anyway).addCaretActionListener
in interface CaretModel
public void runBatchCaretOperation(java.lang.Runnable runnable)
CaretModel
runBatchCaretOperation
in interface CaretModel
public void setCaretsAndSelections(java.util.List<? extends CaretState> caretStates)
CaretModel
System selection will be updated, if such feature is supported by current editor.
setCaretsAndSelections
in interface CaretModel
CaretModel.supportsMultipleCarets()
,
CaretModel.getCaretsAndSelections()
,
CaretModel.setCaretsAndSelections(List, boolean)
public void setCaretsAndSelections(java.util.List<? extends CaretState> caretStates, boolean updateSystemSelection)
CaretModel
System selection will be updated, if such feature is supported by current editor
and corresponding invocation parameter is set to true
.
setCaretsAndSelections
in interface CaretModel
CaretModel.supportsMultipleCarets()
,
CaretModel.getCaretsAndSelections()
public java.util.List<CaretState> getCaretsAndSelections()
CaretModel
CaretModel.getAllCarets()
method results. Passing the result of this method to
CaretModel.setCaretsAndSelections(List)
will restore the state of carets, including the internal caret order, in particular,
the caret, that was primary when this method was called, will be the primary one after corresponding
CaretModel.setCaretsAndSelections(List)
invocation.getCaretsAndSelections
in interface CaretModel
CaretModel.setCaretsAndSelections(List)
public boolean isIteratingOverCarets()
public void onAdded(Inlay inlay)
onAdded
in interface InlayModel.Listener
public void onRemoved(Inlay inlay)
onRemoved
in interface InlayModel.Listener
public void onUpdated(Inlay inlay, int changeFlags)
onUpdated
in interface InlayModel.Listener
changeFlags
- see InlayModel.ChangeFlags
public void onBatchModeFinish(Editor editor)
onBatchModeFinish
in interface InlayModel.Listener
InlayModel.execute(boolean, Runnable)
public void validateState()