Skip to content

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.

csharp
public interface IHex1bDocument

Properties ​

ByteCount ​

Total byte count in the document's underlying byte buffer.

Returns: Int32

csharp
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

csharp
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

csharp
bool IsDirty { get; }

Length ​

Total character count in the document.

Returns: Int32

csharp
int Length { get; }

LineCount ​

Number of lines (at least 1, even for empty documents).

Returns: Int32

csharp
int LineCount { get; }

Version ​

Monotonic version counter, incremented on every edit.

Returns: Int64

csharp
long Version { get; }

Methods ​

Apply(EditOperation, string?) ​

Apply a single character-level edit operation.

Parameters:

Returns: EditResult

csharp
EditResult Apply(EditOperation operation, string? source = null)

Apply(IReadOnlyList<EditOperation>, string?) ​

Apply multiple character-level edit operations atomically.

Parameters:

Returns: EditResult

csharp
EditResult Apply(IReadOnlyList<EditOperation> operations, string? source = null)

ApplyBytes(ByteEditOperation, string?) ​

Apply a byte-level edit operation directly on the byte buffer.

Parameters:

Returns: EditResult

csharp
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.

csharp
void BeginBatch()

EndBatch() ​

End a batch of edits. When the outermost batch ends, caches are rebuilt and a change event is fired.

csharp
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

csharp
Utf8ByteMap GetByteMap()

GetBytes() ​

Get the full document content as raw bytes.

Returns: ReadOnlyMemory<Byte>

csharp
ReadOnlyMemory<byte> GetBytes()

GetBytes(int, int) ​

Get a slice of the document's byte content.

Parameters:

Returns: ReadOnlyMemory<Byte>

csharp
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

csharp
DocumentDiagnosticInfo? GetDiagnosticInfo()

GetLineLength(int) ​

Get the length of a single line (1-based), excluding line ending.

Parameters:

Returns: Int32

csharp
int GetLineLength(int line)

GetLineText(int) ​

Get the text of a single line (1-based).

Parameters:

Returns: String

csharp
string GetLineText(int line)

GetText() ​

Get the full document text (UTF-8 decoded, with U+FFFD for invalid sequences).

Returns: String

csharp
string GetText()

GetText(DocumentRange) ​

Get text within a character range.

Parameters:

Returns: String

csharp
string GetText(DocumentRange range)

OffsetToPosition(DocumentOffset) ​

Convert an absolute character offset to a line/column position.

Parameters:

Returns: DocumentPosition

csharp
DocumentPosition OffsetToPosition(DocumentOffset offset)

PositionToOffset(DocumentPosition) ​

Convert a line/column position to an absolute character offset.

Parameters:

Returns: DocumentOffset

csharp
DocumentOffset PositionToOffset(DocumentPosition position)

SaveAsync(CancellationToken) ​

Saves the document to its . Throws if is null.

Parameters:

Returns: Task

csharp
Task SaveAsync(CancellationToken ct = default)

Events ​

Changed ​

Fired after any edit is applied (character or byte level).

Returns: EventHandler<DocumentChangedEventArgs>

csharp
event EventHandler<DocumentChangedEventArgs>? Changed

Released under the MIT License.