A text edit describes an elementary text manipulation operation. Edits are executed by applying them to a document (e.g. an instance of
IDocument
).
Text edits form a tree. Clients can navigate the tree upwards, from child to parent, as well as downwards. Newly created edits are un-parented. New edits are added to the tree by calling one of the add
methods on a parent edit.
An edit tree is well formed in the following sense:
- a parent edit covers all its children
- children don't overlap
- an edit with length 0 can't have any children
Any manipulation of the tree that violates one of the above requirements results in a
MalformedTreeException
.
Insert edits are represented by an edit of length 0. If more than one insert edit exists at the same offset then the edits are executed in the order in which they have been added to a parent. The following code example:
IDocument document= new Document("org"); MultiTextEdit edit= new MultiTextEdit(); edit.addChild(new InsertEdit(0, "www.")); edit.addChild(new InsertEdit(0, "eclipse.")); edit.apply(document);
therefore results in string: "www.eclipse.org".
Text edits can be executed in a mode where the edit's region is updated to reflect the edit's position in the changed document. Region updating is enabled by default or can be requested by passing UPDATE_REGIONS
to the {@link #apply(IDocument,int) apply(IDocument, int)} method. In the above examplethe region of the InsertEdit(0, "eclipse.")
edit after executing the root edit is [3, 8]
. If the region of an edit got deleted during change execution the region is set to [-1, -1]
and the method {@link #isDeleted() isDeleted} returns true
.
This class isn't intended to be subclassed outside of the edit framework. Clients are only allowed to subclass
MultiTextEdit
.
@since 3.0
@noextend This class is not intended to be subclassed by clients.