In This Article

ITextChange Interface

Provides the base requirements for a text change, which contains one or more ITextChangeOperation objects.

public interface ITextChange

Properties

CanMergeIntoPreviousChange

Gets whether this text change can merge into the previous text change in the undo stack.

bool CanMergeIntoPreviousChange { get; }

Property Value

Boolean:

true if this text change can merge into the previous text change in the undo stack; otherwise, false.

CheckReadOnly

Gets whether to prevent the text change from occurring if any text range to modify is flagged as read-only.

bool CheckReadOnly { get; }

Property Value

Boolean:

true if the read-only state should be checked; otherwise, false.

CustomData

Gets or sets custom data that can be persisted with the text change and restored when undo operations occur later on.

object CustomData { get; set; }

Property Value

Object:

The custom data.

IsMerged

Gets whether this text change is the result of a merge of two or more text changes.

bool IsMerged { get; }

Property Value

Boolean:

true if this text change is the result of a merge of two or more text changes; otherwise, false.

Remarks

A merge can occur when a text change is created with CanMergeIntoPreviousChange.

IsRedo

Gets whether the text change is for a redo.

bool IsRedo { get; }

Property Value

Boolean:

true if the text change is for a redo; otherwise, false.

IsUndo

Gets whether the text change is for an undo.

bool IsUndo { get; }

Property Value

Boolean:

true if the text change is for an undo; otherwise, false.

LastTextReplacementOperationIndex

Gets the index of the last operation within the text change in which the entire document text was replaced, if any.

int LastTextReplacementOperationIndex { get; }

Property Value

Int32:

The index of the last text replacement operation within the text change; otherwise, -1 if there are no such operations.

Operations

Gets the read-only list of ITextChangeOperation objects that make up this text change.

IList<ITextChangeOperation> Operations { get; }

Property Value

IList<ITextChangeOperation>:

The read-only list of ITextChangeOperation objects that make up this text change.

PostSelectionPositionRanges

Gets or sets the collection of sorted non-overlapping TextPositionRange objects that should be selected in the source view after the text change is applied.

ITextPositionRangeCollection PostSelectionPositionRanges { get; set; }

Property Value

ITextPositionRangeCollection:

The collection of sorted non-overlapping TextPositionRange objects that should be selected in the source view after the text change is applied.

PreSelectionPositionRanges

Gets or sets the collection of sorted non-overlapping TextPositionRange objects that were selected in the source view before the text change is applied.

ITextPositionRangeCollection PreSelectionPositionRanges { get; set; }

Property Value

ITextPositionRangeCollection:

The collection of sorted non-overlapping TextPositionRange objects that were selected in the source view before the text change is applied.

RetainSelection

Gets whether to prevent the caret from moving to the end of the text change in the active view.

bool RetainSelection { get; }

Property Value

Boolean:

true if the caret move should be prevented; otherwise, false.

Snapshot

Gets the ITextSnapshot against which all operations in this text change should be based.

ITextSnapshot Snapshot { get; }

Property Value

ITextSnapshot:

The ITextSnapshot against which all operations in this text change should be based.

Source

Gets the optional source of the text change, which is most often an editor view if specified.

object Source { get; }

Property Value

Object:

The optional source of the text change, which is most often an editor view if specified.

Type

Gets an ITextChangeType indicating the type of change that was made.

ITextChangeType Type { get; }

Property Value

ITextChangeType:

An ITextChangeType indicating the type of change that was made.

Methods

AppendText(String)

Adds an ITextChangeOperation that appends text to the end of the Snapshot.

void AppendText(string text)
Parameter Type Description
text String

The text to append to the end of the Snapshot.

Remarks

This method is simply a wrapper for a call to InsertText(Int32, String).

See Also

Apply()

Applies the text change and all of its Operations in sequential order.

bool Apply()

Returns

Boolean:

true if all the operations were applied successfully; otherwise, false.

Apply(ITextPositionRangeCollection, TextRangeTrackingModes)

Applies the text change and all of its Operations in sequential order, also designating the position ranges that should be translated and set to the PostSelectionPositionRanges property after the text change is applied.

bool Apply(ITextPositionRangeCollection pendingSelectionPositionRanges, TextRangeTrackingModes translationTrackingModes)
Parameter Type Description
pendingSelectionPositionRanges ITextPositionRangeCollection

The collection of position ranges that should be converted following the text change.

translationTrackingModes TextRangeTrackingModes

A TextRangeTrackingModes value indicating the translation tracking modes to use.

Returns

Boolean:

true if all the operations were applied successfully; otherwise, false.

Apply(IList<TextRange>, Int32, Nullable<TextRangeTrackingModes>)

Applies the text change and all of its Operations in sequential order, also designating the text ranges that should be converted and set to the PostSelectionPositionRanges property after the text change is applied.

bool Apply(IList<TextRange> pendingSelectionTextRanges, int primaryIndex, TextRangeTrackingModes? translationTrackingModes)
Parameter Type Description
pendingSelectionTextRanges IList<TextRange>

The collection of text ranges that should be converted following the text change.

primaryIndex Int32

The index of the primary selection range.

translationTrackingModes Nullable<TextRangeTrackingModes>

When the text range offsets are relative to the previous snapshot and need to be translated to the new snapshot, this parameter should be set to a non-null TextRangeTrackingModes value indicating the translation tracking modes to use. A null value indicates no translation is necessary since the text range offsets are relative to the new snapshot.

Returns

Boolean:

true if all the operations were applied successfully; otherwise, false.

DeleteText(TextRange)

Adds an ITextChangeOperation that deletes text in the Snapshot.

void DeleteText(TextRange textRange)
Parameter Type Description
textRange TextRange

The TextRange of offsets to delete.

See Also

DeleteText(Int32, Int32)

Adds an ITextChangeOperation that deletes text in the Snapshot.

void DeleteText(int offset, int deleteLength)
Parameter Type Description
offset Int32

The starting offset at which to delete.

deleteLength Int32

The number of characters to delete.

See Also

InsertText(Int32, String)

Adds an ITextChangeOperation that inserts text in the Snapshot.

void InsertText(int offset, string text)
Parameter Type Description
offset Int32

The offset at which to insert.

text String

The text to insert.

See Also

ReplaceText(TextRange, String)

Adds an ITextChangeOperation that replaces text in the Snapshot.

void ReplaceText(TextRange textRange, string insertText)
Parameter Type Description
textRange TextRange

The TextRange of offsets to delete.

insertText String

The text to insert.

See Also

ReplaceText(Int32, Int32, String)

Adds an ITextChangeOperation that replaces text in the Snapshot.

void ReplaceText(int offset, int deleteLength, string insertText)
Parameter Type Description
offset Int32

The offset at which to insert.

deleteLength Int32

The number of characters to delete before inserting the text.

insertText String

The text to insert.

See Also

SetText(String)

Adds an ITextChangeOperation that replaces all the text in the Snapshot and marks the operation as a programmatic replacement.

void SetText(string text)
Parameter Type Description
text String

The text to insert. Pass an empty string to "clear" the document.

Remarks

A programmatic text replacement means that the undo history will be cleared, and any attached editors will reset the caret to offset 0.

See Also

SetText(String, Boolean)

Adds an ITextChangeOperation that replaces all the text in the Snapshot and optionally marks the operation as a programmatic replacement.

void SetText(string text, bool isProgrammatic)
Parameter Type Description
text String

The text to insert. Pass an empty string to "clear" the document.

isProgrammatic Boolean

Whether the operation is considered a programmatic replacement.

Remarks

A programmatic text replacement means that the undo history will be cleared, and any attached editors will reset the caret to offset 0.

See Also