IHex1bDocument
Namespace: Hex1b.Documents
Assembly: Hex1b.dll
Interface for a document that can be read, edited, and observed. The document model is UI-independent and collaboration-ready. Supports both character-level and byte-level access.
public interface IHex1bDocumentProperties
ByteCount
Total byte count in the document's underlying byte buffer.
Returns: Int32
int ByteCount { get; }FilePath
The file path this document is associated with, or null for in-memory documents. Set when a document is opened from or saved to a file via a workspace.
Returns: String
string? FilePath { get; }IsDirty
Whether the document has unsaved changes. Always false for documents without a . Set to true on any edit after the last save.
Returns: Boolean
bool IsDirty { get; }Length
Total character count in the document.
Returns: Int32
int Length { get; }LineCount
Number of lines (at least 1, even for empty documents).
Returns: Int32
int LineCount { get; }Version
Monotonic version counter, incremented on every edit.
Returns: Int64
long Version { get; }Methods
Apply(EditOperation, string?)
Apply a single character-level edit operation.
Parameters:
operation(EditOperation):source(String):
Returns: EditResult
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
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
EditResult ApplyBytes(ByteEditOperation operation, string? source = null)BeginBatch()
Begin a batch of edits. Cache rebuilds and change events are deferred until the matching call. Batches may be nested.
void BeginBatch()EndBatch()
End a batch of edits. When the outermost batch ends, caches are rebuilt and a change event is fired.
void EndBatch()GetByteMap()
Returns a cached byte↔char mapping for the current document content. The default implementation builds a new map on each call; implementations should cache and invalidate on edit for performance.
Returns: Utf8ByteMap
Utf8ByteMap GetByteMap()GetBytes()
Get the full document content as raw bytes.
Returns: ReadOnlyMemory<Byte>
ReadOnlyMemory<byte> GetBytes()GetBytes(int, int)
Get a slice of the document's byte content.
Parameters:
Returns: ReadOnlyMemory<Byte>
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
DocumentDiagnosticInfo? GetDiagnosticInfo()GetLineLength(int)
Get the length of a single line (1-based), excluding line ending.
Parameters:
line(Int32):
Returns: Int32
int GetLineLength(int line)GetLineText(int)
Get the text of a single line (1-based).
Parameters:
line(Int32):
Returns: String
string GetLineText(int line)GetText()
Get the full document text (UTF-8 decoded, with U+FFFD for invalid sequences).
Returns: String
string GetText()GetText(DocumentRange)
Get text within a character range.
Parameters:
range(DocumentRange):
Returns: String
string GetText(DocumentRange range)OffsetToPosition(DocumentOffset)
Convert an absolute character offset to a line/column position.
Parameters:
offset(DocumentOffset):
Returns: DocumentPosition
DocumentPosition OffsetToPosition(DocumentOffset offset)PositionToOffset(DocumentPosition)
Convert a line/column position to an absolute character offset.
Parameters:
position(DocumentPosition):
Returns: DocumentOffset
DocumentOffset PositionToOffset(DocumentPosition position)SaveAsync(CancellationToken)
Saves the document to its . Throws if is null.
Parameters:
ct(CancellationToken):
Returns: Task
Task SaveAsync(CancellationToken ct = default)Events
Changed
Fired after any edit is applied (character or byte level).
Returns: EventHandler<DocumentChangedEventArgs>
event EventHandler<DocumentChangedEventArgs>? Changed