Hex1bDocument
Namespace: Hex1b.Documents
Assembly: Hex1b.dll
Default IHex1bDocument implementation backed by a piece table. Internally byte-oriented: the piece table operates on UTF-8 byte sequences. Character-level API (GetText, Length, OffsetToPosition) is derived from bytes.
public sealed class Hex1bDocument : IHex1bDocumentInheritance
Object → Hex1bDocument
Implements
Constructors
Hex1bDocument(byte[])
Creates a document from raw bytes (not necessarily valid UTF-8).
Parameters:
initialBytes(Byte[]):
public Hex1bDocument(byte[] initialBytes)Hex1bDocument(string)
Parameters:
initialText(String):
public Hex1bDocument(string initialText = "")Properties
ByteCount
Total byte count in the document's underlying byte buffer.
Returns: Int32
public int ByteCount { get; }FilePath
The file path this document is associated with, or null for in-memory documents.
Returns: String
public string? FilePath { get; }IsDirty
Whether the document has unsaved changes since the last save or load. Always false for documents without a .
Returns: Boolean
public bool IsDirty { get; }Length
Total character count in the document.
Returns: Int32
public int Length { get; }LineCount
Number of lines (at least 1, even for empty documents).
Returns: Int32
public int LineCount { get; }Version
Monotonic version counter, incremented on every edit.
Returns: Int64
public long Version { get; }Methods
Apply(EditOperation, string?)
Apply a single character-level edit operation.
Parameters:
operation(EditOperation):source(String):
Returns: EditResult
public EditResult Apply(EditOperation operation, string? source = null)Apply(IReadOnlyList<EditOperation>, string?)
Apply multiple character-level edit operations atomically.
Parameters:
operations(IReadOnlyList<EditOperation>):source(String):
Returns: EditResult
public EditResult Apply(IReadOnlyList<EditOperation> operations, string? source = null)ApplyBytes(ByteEditOperation, string?)
Apply a byte-level edit operation directly on the byte buffer.
Parameters:
operation(ByteEditOperation):source(String):
Returns: EditResult
public EditResult ApplyBytes(ByteEditOperation operation, string? source = null)BeginBatch()
Begins a batch of edits. While a batch is open, and events are deferred until is called. Batches may be nested; only the outermost triggers the rebuild.
This is critical for multi-cursor edits: without batching, each cursor's edit triggers a full O(n) cache rebuild (assemble bytes + UTF-8 decode + line scan). With batching, all piece-tree mutations happen first, then a single O(n) rebuild.
public void BeginBatch()EndBatch()
Ends a batch of edits. When the outermost batch ends, rebuilds all caches once and fires a single event.
public void EndBatch()GetByteMap()
Returns a cached byte↔char mapping. The map is lazily rebuilt when the document changes and reused across calls within the same document version.
Returns: Utf8ByteMap
public Utf8ByteMap GetByteMap()GetBytes()
Get the full document content as raw bytes.
Returns: ReadOnlyMemory<Byte>
public ReadOnlyMemory<byte> GetBytes()GetBytes(int, int)
Get a slice of the document's byte content.
Parameters:
Returns: ReadOnlyMemory<Byte>
public ReadOnlyMemory<byte> GetBytes(int byteOffset, int count)GetDiagnosticInfo()
Returns a diagnostic snapshot of the document's internal structure. Returns null if the implementation does not support diagnostics.
Returns: DocumentDiagnosticInfo
public DocumentDiagnosticInfo GetDiagnosticInfo()GetLineLength(int)
Get the length of a single line (1-based), excluding line ending.
Parameters:
line(Int32):
Returns: Int32
public int GetLineLength(int line)GetLineText(int)
Get the text of a single line (1-based).
Parameters:
line(Int32):
Returns: String
public string GetLineText(int line)GetText()
Get the full document text (UTF-8 decoded, with U+FFFD for invalid sequences).
Returns: String
public string GetText()GetText(DocumentRange)
Get text within a character range.
Parameters:
range(DocumentRange):
Returns: String
public string GetText(DocumentRange range)OffsetToPosition(DocumentOffset)
Convert an absolute character offset to a line/column position.
Parameters:
offset(DocumentOffset):
Returns: DocumentPosition
public DocumentPosition OffsetToPosition(DocumentOffset offset)PositionToOffset(DocumentPosition)
Convert a line/column position to an absolute character offset.
Parameters:
position(DocumentPosition):
Returns: DocumentOffset
public DocumentOffset PositionToOffset(DocumentPosition position)SaveAsync(CancellationToken)
Saves the document content to its .
Parameters:
ct(CancellationToken):
Returns: Task
public Task SaveAsync(CancellationToken ct = default)Events
Changed
Fired after any edit is applied (character or byte level).
Returns: EventHandler<DocumentChangedEventArgs>
public event EventHandler<DocumentChangedEventArgs>? Changed