public abstract class DocumentEvent
extends java.util.EventObject
Modifier | Constructor and Description |
---|---|
protected |
DocumentEvent(Document document) |
Modifier and Type | Method and Description |
---|---|
Document |
getDocument() |
int |
getMoveOffset()
In case of any document modifications other than moving text, this method returns the same as
getOffset() . |
abstract java.lang.CharSequence |
getNewFragment() |
abstract int |
getNewLength() |
abstract int |
getOffset()
The start offset of a text change.
|
abstract java.lang.CharSequence |
getOldFragment() |
abstract int |
getOldLength() |
abstract long |
getOldTimeStamp() |
boolean |
isWholeTextReplaced() |
protected DocumentEvent(Document document)
public Document getDocument()
public abstract int getOffset()
public int getMoveOffset()
getOffset()
.
Moving a text fragment using DocumentEx.moveText(int, int, int)
is accomplished by a combination of
insertion and deletion. For these two events this method returns the offset of the complementary deletion/insertion event: DocumentListener.documentChanged(com.intellij.openapi.editor.event.DocumentEvent)
of the insertion event, and
b) during DocumentListener.beforeDocumentChange(com.intellij.openapi.editor.event.DocumentEvent)
of the deletion event.
In order to obtain an adjusted value before the new fragment is inserted or after deleting the original one, consider using
the DocumentEventUtil.getMoveOffsetBeforeInsertion(com.intellij.openapi.editor.event.DocumentEvent)
and the DocumentEventUtil.getMoveOffsetAfterDeletion(com.intellij.openapi.editor.event.DocumentEvent)
methods, accordingly.
Examples:
Moving text to the left:
document.moveText(2, 6, 0); // aa^^^^bb -> ^^^^aa^^^^bb -> ^^^^aabbIn this example the following listener calls are performed:
beforeDocumentChange(insert): aa^^^^bb [ offset: 0, oldLength: 0, newLength: 4, moveOffset: 6, moveOffsetBeforeInsertion: 2 ] documentChanged(insert): ^^^^aa^^^^bb [ offset: 0, oldLength: 0, newLength: 4, moveOffset: 6 ] // moveOffset == delete.offset beforeDocumentChange(delete): ^^^^aa^^^^bb [ offset: 6, oldLength: 4, newLength: 0, moveOffset: 0 ] // moveOffset == insert.offset documentChanged(delete): ^^^^aabb [ offset: 6, oldLength: 4, newLength: 0, moveOffset: 0, moveOffsetAfterDeletion: 0 ]Moving text to the right:
document.moveText(2, 6, 8); // aa^^^^bb -> aa^^^^bb^^^^ -> aabb^^^^In this example the following listener calls are performed:
beforeDocumentChange(insert): aa^^^^bb [ offset: 8, oldLength: 0, newLength: 4, moveOffset: 2, moveOffsetBeforeInsertion: 2 ] documentChanged(insert): aa^^^^bb^^^^ [ offset: 8, oldLength: 0, newLength: 4, moveOffset: 2 ] // moveOffset == delete.offset beforeDocumentChange(delete): aa^^^^bb^^^^ [ offset: 2, oldLength: 4, newLength: 0, moveOffset: 8 ] // moveOffset == insert.offset documentChanged(delete): aabb^^^^ [ offset: 2, oldLength: 4, newLength: 0, moveOffset: 8, moveOffsetAfterDeletion: 4 ]
public abstract int getOldLength()
public abstract int getNewLength()
public abstract java.lang.CharSequence getOldFragment()
public abstract java.lang.CharSequence getNewFragment()
public abstract long getOldTimeStamp()
public boolean isWholeTextReplaced()