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.
public class CursorSet : IReadOnlyList<DocumentCursor>, IReadOnlyCollection<DocumentCursor>, IEnumerable<DocumentCursor>, IEnumerableInheritance
Object → CursorSet
Implements
- IReadOnlyList<DocumentCursor>
- IReadOnlyCollection<DocumentCursor>
- IEnumerable<DocumentCursor>
- IEnumerable
Constructors
CursorSet()
public CursorSet()Properties
Count
Number of cursors.
Returns: Int32
public int Count { get; }Primary
The primary cursor (receives focus, used for single-cursor operations).
Returns: DocumentCursor
public DocumentCursor Primary { get; }PrimaryIndex
Index of the primary cursor within the sorted list.
Returns: Int32
public int PrimaryIndex { get; }this[int]
Access cursor by index (sorted order).
Parameters:
index(Int32):
Returns: DocumentCursor
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:
position(DocumentOffset):selectionAnchor(Nullable<DocumentOffset>):
Returns: Int32
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:
position(DocumentOffset):
Returns: Int32
public int Add(DocumentOffset position)ClampAll(int)
Clamp all cursors to valid document range.
Parameters:
documentLength(Int32):
public void ClampAll(int documentLength)CollapseToSingle()
Remove all cursors except the primary.
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.
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>>
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.
public void MergeOverlapping()RemoveAt(int)
Remove the cursor at the given index. Cannot remove the last cursor.
Parameters:
index(Int32):
public void RemoveAt(int index)Restore(CursorSetSnapshot)
Restore cursor positions from a snapshot.
Parameters:
snapshot(CursorSetSnapshot):
public void Restore(CursorSetSnapshot snapshot)Snapshot()
Create a snapshot of all cursor positions and selections for undo/redo.
Returns: CursorSetSnapshot
public CursorSetSnapshot Snapshot()Sort()
Re-sort cursors after position changes. Tracks primary cursor through the sort.
public void Sort()