public class CaretModelImpl extends java.lang.Object implements CaretModel, PrioritizedDocumentListener, Disposable, Dumpable, InlayModel.Listener
Disposable.ParentCOMPARATORARRAY_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, waitaddCaret, addCaretListener, getLogicalPosition, getOffset, getVisualLineEnd, getVisualLineStart, getVisualPosition, isUpToDate, moveCaretRelatively, moveToLogicalPosition, moveToOffset, moveToOffset, moveToVisualPositionbulkUpdateFinished, bulkUpdateStartingonBatchModeStart, onUpdatedpublic CaretModelImpl(EditorImpl editor)
public void documentChanged(DocumentEvent e)
DocumentListenerdocumentChanged in interface DocumentListenere - the event containing the information about the change.public void beforeDocumentChange(DocumentEvent e)
DocumentListenerbeforeDocumentChange in interface DocumentListenere - the event containing the information about the change.public int getPriority()
getPriority in interface PrioritizedDocumentListenerpublic void dispose()
Disposabledispose in interface Disposablepublic void updateVisualPosition()
public void addCaretListener(CaretListener listener)
CaretModeladdCaretListener in interface CaretModellistener - the listener instance.public void removeCaretListener(CaretListener listener)
CaretModelremoveCaretListener in interface CaretModellistener - the listener instance.public TextAttributes getTextAttributes()
CaretModelgetTextAttributes in interface CaretModelpublic void reinitSettings()
public boolean supportsMultipleCarets()
CaretModelsupportsMultipleCarets in interface CaretModelpublic CaretImpl getCurrentCaret()
CaretModelCaretModel.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 CaretModelpublic CaretImpl getPrimaryCaret()
CaretModelgetPrimaryCaret in interface CaretModelpublic int getCaretCount()
CaretModelgetCaretCount in interface CaretModelpublic java.util.List<Caret> getAllCarets()
CaretModelgetAllCarets in interface CaretModelpublic Caret getCaretAt(VisualPosition pos)
CaretModelnull, if there's no caret there.getCaretAt in interface CaretModelpublic Caret addCaret(VisualPosition pos, boolean makePrimary)
CaretModelCaret 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 CaretModelpublic Caret addCaret(LogicalPosition pos, boolean makePrimary)
CaretModelCaret 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 CaretModelpublic boolean removeCaret(Caret caret)
CaretModeltrue.
false is returned if any of the above condition doesn't hold, and the removal cannot happen.removeCaret in interface CaretModelpublic void removeSecondaryCarets()
CaretModelremoveSecondaryCarets in interface CaretModelpublic void runForEachCaret(CaretAction action)
CaretModelrunForEachCaret in interface CaretModelpublic 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 CaretModelpublic void addCaretActionListener(CaretActionListener listener, Disposable disposable)
CaretModelCaretModel.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 CaretModelpublic void runBatchCaretOperation(java.lang.Runnable runnable)
CaretModelrunBatchCaretOperation in interface CaretModelpublic void setCaretsAndSelections(java.util.List<? extends CaretState> caretStates)
CaretModelSystem selection will be updated, if such feature is supported by current editor.
setCaretsAndSelections in interface CaretModelCaretModel.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 CaretModelCaretModel.supportsMultipleCarets(),
CaretModel.getCaretsAndSelections()public java.util.List<CaretState> getCaretsAndSelections()
CaretModelCaretModel.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 CaretModelCaretModel.setCaretsAndSelections(List)public boolean isIteratingOverCarets()
public void onAdded(Inlay inlay)
onAdded in interface InlayModel.Listenerpublic void onRemoved(Inlay inlay)
onRemoved in interface InlayModel.Listenerpublic void onUpdated(Inlay inlay, int changeFlags)
onUpdated in interface InlayModel.ListenerchangeFlags - see InlayModel.ChangeFlagspublic void onBatchModeFinish(Editor editor)
onBatchModeFinish in interface InlayModel.ListenerInlayModel.execute(boolean, Runnable)public void validateState()