Table of Contents

Class TextChangeSet

Namespace
Icy.Design.Text
Assembly
IcyUI.Design.dll

An ordered set of non-overlapping TextChanges, all expressed against the same original text.

public sealed class TextChangeSet : IReadOnlyList<TextChange>, IReadOnlyCollection<TextChange>, IEnumerable<TextChange>, IEnumerable
Inheritance
TextChangeSet
Implements
Inherited Members
Extension Methods

Remarks

The changes are kept sorted by start offset. Two changes may touch, but they can't overlap, and at most one pure insertion may sit at any offset, so applying the set is unambiguous.

A change set is the unit every edit of a design document produces, and the unit a future text editor receives to update its buffer without losing its caret or its own undo history.

Constructors

TextChangeSet(IEnumerable<TextChange>)

Initializes a new instance of the TextChangeSet class.

public TextChangeSet(IEnumerable<TextChange> changes)

Parameters

changes IEnumerable<TextChange>

The changes, in any order.

Exceptions

ArgumentNullException

changes is null.

ArgumentException

A change has null new text, two changes overlap, or two insertions share an offset.

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

Empty

Gets a change set that changes nothing.

public static TextChangeSet Empty { get; }

Property Value

TextChangeSet

this[int]

Gets the element at the specified index in the read-only list.

public TextChange this[int index] { get; }

Parameters

index int

The zero-based index of the element to get.

Property Value

TextChange

The element at the specified index in the read-only list.

Methods

Apply(string)

Applies every change to text in one pass.

public string Apply(string text)

Parameters

text string

The original text the changes were expressed against.

Returns

string

The changed text.

Exceptions

ArgumentNullException

text is null.

ArgumentException

A change lies outside text.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<TextChange> GetEnumerator()

Returns

IEnumerator<TextChange>

An enumerator that can be used to iterate through the collection.

Invert(string)

Creates the change set that turns the changed text back into originalText.

public TextChangeSet Invert(string originalText)

Parameters

originalText string

The text this set was expressed against.

Returns

TextChangeSet

The inverse change set, expressed against the changed text.

Exceptions

ArgumentNullException

originalText is null.

MapPosition(int)

Maps an offset in the original text to the same character's offset in the changed text.

public int? MapPosition(int position)

Parameters

position int

An offset in the original text.

Returns

int?

The offset in the changed text, or null when the character at position was replaced or deleted. An insertion exactly at position counts as coming before it, so the character shifts past the inserted text.