Back to API Reference
Class

Rope

sealed
Inherits:ITextDocument
Implements:IDisposable

The document: a flat table of TextBlock leaves with Fenwick indexes over chars, codepoints, paragraph separators, heights and widths. Every position query — char↔codepoint, char↔paragraph, Y↔block, X↔block — is O(log blocks); an edit costs O(edited block) plus O(log blocks), or O(blocks) when it changes the block count. Blocks lent to workers through Lease are immutable for the lease's lifetime: an edit clones a shared block instead of mutating it.

Remarks

Main-thread only, except for reads through a BlockLease. Block boundaries never split a surrogate pair or a CRLF pair; edits may not split a surrogate pair (they throw), matching ITextDocument consumers' expectations.
public ScanProfile Profile{ get; set }

The scan profile blocks are classified with; changing it re-summarizes every block.

public int CodepointCount{ get }
public int CharCount{ get }
public int Length{ get }

Logical length in UTF-16 units; the same value as CharCount.

public int Version{ get }
public int ParagraphCount{ get }

Paragraphs, counting the (possibly empty) one after the last separator; never zero.

public int BlockCount{ get }
public bool IsEmpty{ get }
public int MeasuredBlockCount{ get }

Blocks whose extent is an exact measurement rather than an estimate.

public double TotalHeight{ get }
public float ContentWidth{ get }

Widest extent seen so far under the current layout; monotonic until ResetLayout.

[ctor]public Rope()

Creates an empty document.

public static Rope FromChars()

Builds a document from UTF-16 text, cutting blocks at paragraph boundaries where possible.

public void Dispose()

Releases every block reference this document holds and the loaded source, if any.

[ctor]public Rope()

Creates an empty document; capacity is accepted for call-site compatibility and has no effect on block sizing.

public int BlockAtChar()

Block containing logical char charIndex; an index at the end maps to the last block's end.

public int BlockAtCodepoint()
public int BlockCharStart()
public int BlockCodepointStart()
public int BlockCharCount()
public int BlockCodepointCount()
public int BlockSeparatorCount()
public TextBlockFlags BlockFlags()
public bool BlockStartsParagraph()

True when the block begins a paragraph: it is the first block or its predecessor ends with a separator.

public bool BlockEndsParagraph()
public int BlockFirstParagraph()

Index of the first paragraph that starts inside or continues into the block.

public int CharToParagraph()

Zero-based paragraph containing logical char charIndex.

public int ParagraphStartChar()

Logical char index where paragraph paragraph starts.

public int CharToCodepointIndex()
public int CodepointToCharIndex()
public int CopyChars()

Copies logical chars [start, start+count); returns the number copied (clamped to the document and the destination).

public int CopyCodepointRange()
public int CopyTo()

Copies the whole content; returns the number of chars written.

public int CopyTo()

Copies logical chars [start, start+count); returns the number written.

public string GetCodepointRange()

The text of a codepoint range as a new string.

public int SnapToPairBoundary()

Clamps to [0, Length] and snaps an interior surrogate boundary backward.

public int CountCodepoints()

Codepoints in a logical char range.

public int GetCodepointAt()
public bool ContentEquals()

True when the content equals other unit for unit; compares block by block without allocating.

public override string ToString()

The document as a string; allocates the whole text.

public EditShape Insert()
public EditShape Delete()
public EditShape InsertAtCodepoint()
public EditShape DeleteAtCodepoint()
public EditShape SetText()

Replaces the whole content; the returned shape excludes the common prefix and suffix.

public void Clear()
public EditShape Replace()

The one mutation: removes removeCount chars at start and inserts text there. Boundaries may not split a surrogate pair.

public void ResetLayout()

Resets every block's extent to an estimate under new layout parameters.

public void RefineEstimate()

Updates the estimation parameters without discarding measured blocks; provisional blocks are re-estimated.

public void SetBlockMeasured()

Records a block's measured extent; it stays until the block is edited or the layout is reset. A measurement taken with the block's paragraph cut at a window edge is exact =: it replaces the estimate but leaves the block for the convergence sweep, and it never overwrites an exact measurement.

public bool IsBlockExact()

True when the block's extent was measured with its paragraph intact.

public double BlockTop()
public double BlockHeight()
public double BlockWidth()
public double BlockLeftInParagraph()

Horizontal offset of the block from the start of its paragraph — meaningful when the paragraph spans several blocks.

public int BlockAtY()

Block whose vertical span contains y (document space, top-down), clamped to the table.

public BlockLease Lease()

Pins blocks [first, first+count) for a worker: their content stays immutable until Dispose (main thread). Reads through the lease are safe from any thread.