Package org.eclipse.jface.text
Class DefaultPositionUpdater
java.lang.Object
org.eclipse.jface.text.DefaultPositionUpdater
- All Implemented Interfaces:
IPositionUpdater
- Direct Known Subclasses:
MultiPassContentFormatter.NonDeletingPositionUpdater
Default implementation of
IPositionUpdater
.
A default position updater must be configured with the position category whose positions it will update. Other position categories are not affected by this updater.
This implementation follows the specification below:
- Inserting or deleting text before the position shifts the position accordingly.
- Inserting text at the position offset shifts the position accordingly.
- Inserting or deleting text strictly contained by the position shrinks or stretches the position.
- Inserting or deleting text after a position does not affect the position.
- Deleting text which strictly contains the position deletes the position. Note that the position is not deleted if its only shrunken to length zero. To delete a position, the modification must delete from strictly before to strictly after the position.
- Replacing text contained by the position shrinks or expands the position (but does not shift it), such that the final position contains the original position and the replacing text.
- Replacing text overlapping the position in other ways is considered as a sequence of first deleting the replaced text and afterwards inserting the new text. Thus, a position is shrunken and can then be shifted (if the replaced text overlaps the offset of the position).
-
Field Summary
Modifier and TypeFieldDescriptionprotected IDocument
Caches the documentprotected int
Caches the length of the replaced textprotected int
Caches the offset of the replaced textprotected Position
Caches the original state of the investigated positionprotected Position
Caches the currently investigated positionprotected int
Caches the length of the newly inserted text -
Constructor Summary
ConstructorDescriptionDefaultPositionUpdater
(String category) Creates a new default position updater for the given category. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adapts the currently investigated position to an insertion.protected void
Adapts the currently investigated position to a deletion.protected void
Adapts the currently investigated position to the replace operation.protected String
Returns the category this updater is responsible for.protected boolean
Returns whether the current event describes a well formed replace by which the current position is directly affected.protected boolean
Determines whether the currently investigated position has been deleted by the replace operation specified in the current event.void
update
(DocumentEvent event) Adapts positions to the change specified by the document event.
-
Field Details
-
fPosition
Caches the currently investigated position -
fOriginalPosition
Caches the original state of the investigated position -
fOffset
protected int fOffsetCaches the offset of the replaced text -
fLength
protected int fLengthCaches the length of the replaced text -
fReplaceLength
protected int fReplaceLengthCaches the length of the newly inserted text -
fDocument
Caches the document
-
-
Constructor Details
-
DefaultPositionUpdater
Creates a new default position updater for the given category.- Parameters:
category
- the category the updater is responsible for
-
-
Method Details
-
getCategory
Returns the category this updater is responsible for.- Returns:
- the category this updater is responsible for
-
isAffectingReplace
protected boolean isAffectingReplace()Returns whether the current event describes a well formed replace by which the current position is directly affected.- Returns:
true
the current position is directly affected- Since:
- 3.0
-
adaptToInsert
protected void adaptToInsert()Adapts the currently investigated position to an insertion. -
adaptToRemove
protected void adaptToRemove()Adapts the currently investigated position to a deletion. -
adaptToReplace
protected void adaptToReplace()Adapts the currently investigated position to the replace operation. First it checks whether the change replaces only a non-zero range inside the range of the position (including the borders). If not, it performs first the deletion of the previous text and afterwards the insertion of the new text. -
notDeleted
protected boolean notDeleted()Determines whether the currently investigated position has been deleted by the replace operation specified in the current event. If so, it deletes the position and removes it from the document's position category.- Returns:
true
if position has not been deleted
-
update
Description copied from interface:IPositionUpdater
Adapts positions to the change specified by the document event. It is ensured that the document's partitioning has been adapted to this document change and that all the position updaters which have a smaller index in the document's position updater list have been called.- Specified by:
update
in interfaceIPositionUpdater
- Parameters:
event
- the document event describing the document change
-