Skip to content

CursorSet

Namespace: Hex1b.Documents

Assembly: Hex1b.dll

A sorted, non-overlapping collection of document cursors. Cursors are maintained in ascending order by position. After multi-cursor operations, overlapping cursors are automatically merged.

csharp
public class CursorSet : IReadOnlyList<DocumentCursor>, IReadOnlyCollection<DocumentCursor>, IEnumerable<DocumentCursor>, IEnumerable

Inheritance

ObjectCursorSet

Implements

Constructors

CursorSet()

csharp
public CursorSet()

Properties

Count

Number of cursors.

Returns: Int32

csharp
public int Count { get; }

Primary

The primary cursor (receives focus, used for single-cursor operations).

Returns: DocumentCursor

csharp
public DocumentCursor Primary { get; }

PrimaryIndex

Index of the primary cursor within the sorted list.

Returns: Int32

csharp
public int PrimaryIndex { get; }

this[int]

Access cursor by index (sorted order).

Parameters:

Returns: DocumentCursor

csharp
public DocumentCursor this[int index] { get; }

Methods

Add(DocumentOffset, DocumentOffset?)

Add a new cursor with a selection. The cursor is inserted in sorted order. Returns the index of the newly added cursor.

Parameters:

Returns: Int32

csharp
public int Add(DocumentOffset position, DocumentOffset? selectionAnchor)

Add(DocumentOffset)

Add a new cursor at the given offset. The cursor is inserted in sorted order. Returns the index of the newly added cursor.

Parameters:

Returns: Int32

csharp
public int Add(DocumentOffset position)

ClampAll(int)

Clamp all cursors to valid document range.

Parameters:

csharp
public void ClampAll(int documentLength)

CollapseToSingle()

Remove all cursors except the primary.

csharp
public void CollapseToSingle()

GetEnumerator()

Returns an enumerator that iterates through the collection.

Returns: IEnumerator<DocumentCursor>

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

csharp
public IEnumerator<DocumentCursor> GetEnumerator()

InReverseOrder()

Iterate cursors in reverse document order (highest offset first). Use this when applying edits to avoid offset invalidation.

Returns: IEnumerable<DocumentCursor, Int32>>

csharp
public IEnumerable<(DocumentCursor Cursor, int Index)> InReverseOrder()

MergeOverlapping()

Merge overlapping or adjacent cursors, preserving the primary where possible. Call this after operations that may cause cursor positions to overlap.

csharp
public void MergeOverlapping()

RemoveAt(int)

Remove the cursor at the given index. Cannot remove the last cursor.

Parameters:

csharp
public void RemoveAt(int index)

Restore(CursorSetSnapshot)

Restore cursor positions from a snapshot.

Parameters:

csharp
public void Restore(CursorSetSnapshot snapshot)

Snapshot()

Create a snapshot of all cursor positions and selections for undo/redo.

Returns: CursorSetSnapshot

csharp
public CursorSetSnapshot Snapshot()

Sort()

Re-sort cursors after position changes. Tracks primary cursor through the sort.

csharp
public void Sort()

Released under the MIT License.