5#include <portals/model_position.hpp>
6#include <portals/text_history.hpp>
40class TextChangeMap final {
51 std::uint64_t initialRevision = 1,
52 std::uint64_t initialContentState = 1);
58 std::expected<void, SourceError>
edit(
TextSplice change, std::uint64_t contentState)
noexcept;
63 std::expected<void, SourceError>
traverse(std::uint64_t contentState, std::uint64_t
extent)
noexcept;
68 std::expected<ModelBookmark, SourceError>
bookmark(std::uint64_t offset,
79 std::uint64_t
extent() const noexcept;
83 explicit TextChangeMap(std::unique_ptr<State> state) noexcept;
84 std::unique_ptr<State> state_;
124 std::string_view
target() const noexcept;
129 friend class FiniteTextDocument;
131 std::shared_ptr<const State> state_;
192 std::stop_token stop = {})
const override;
196 std::expected<TextSaveTicket, TextDocumentError>
beginSave(std::string_view target);
218 explicit FiniteTextDocument(std::unique_ptr<State> state) noexcept;
220 std::unique_ptr<State> state_;
std::expected< void, TextDocumentError > redo()
std::expected< void, TextDocumentError > replace(std::size_t begin, std::size_t end, std::string_view replacement, TextHistoryKind kind=TextHistoryKind::PROGRAMMATIC)
bool canUndo() const noexcept
std::uint64_t revision() const noexcept
TextSelection selection() const noexcept
const GraphemeText & text() const noexcept
std::expected< void, TextDocumentError > setSelection(TextSelection selection) noexcept
std::expected< void, TextDocumentError > acceptExternalReplacement(std::string_view text)
std::expected< ModelBookmark, SourceError > bookmark(std::size_t byteOffset, PositionAffinity affinity=PositionAffinity::FORWARD) const
bool conflicted() const noexcept
std::string_view saveTarget() const noexcept
static std::expected< std::unique_ptr< FiniteTextDocument >, TextDocumentError > create(std::string_view text, FiniteTextDocumentOptions options={})
SourceStamp session() const noexcept
bool canRedo() const noexcept
std::expected< void, TextDocumentError > undo()
bool dirty() const noexcept
ModelResource resource() const noexcept
std::expected< PositionReply, SourceError > resolve(const PositionRequest &request, std::stop_token stop={}) const override
~FiniteTextDocument() override
Release only this session's own text, history and metadata.
void observeExternalReplacement() noexcept
Report external replacement without accepting unrelated bytes or clearing history.
std::expected< void, TextDocumentError > acknowledgeSave(const TextSaveTicket &ticket) noexcept
std::expected< TextSaveTicket, TextDocumentError > beginSave(std::string_view target)
Owning validated UTF-8 and immutable extended grapheme measurements.
Definition text.hpp:145
Copyable bookmark owning metadata only; never retains model, snapshot, view or page....
Definition model_position.hpp:66
Bounded provider extension independent of views, schedulers, and total extent. Implementations must n...
Definition model_position.hpp:163
std::uint64_t revision() const noexcept
std::uint64_t extent() const noexcept
std::expected< void, SourceError > edit(TextSplice change, std::uint64_t contentState) noexcept
~TextChangeMap()
Release metadata; no provider, view or text is retained.
std::expected< ModelBookmark, SourceError > bookmark(std::uint64_t offset, PositionAffinity affinity=PositionAffinity::FORWARD) const
std::expected< void, SourceError > traverse(std::uint64_t contentState, std::uint64_t extent) noexcept
static std::expected< std::unique_ptr< TextChangeMap >, SourceError > create(ModelResource resource, std::uint64_t extent, TextAnchorOptions options={}, std::uint64_t initialRevision=1, std::uint64_t initialContentState=1)
std::expected< TextMappedPosition, SourceError > map(const ModelBookmark &bookmark, std::stop_token stop={}) const
Owning save acknowledgement qualification; retains target metadata, never document bytes....
Definition text_document.hpp:120
std::uint64_t revision() const noexcept
std::string_view target() const noexcept
TextSaveTicket()=default
Empty invalid ticket.
Public Portals API.
Definition action.hpp:8
PositionAffinity
Preferred surviving side when a position is deleted or text is inserted beside a mark.
Definition model_position.hpp:42
@ FORWARD
Prefer the following item; an end boundary falls back to the preceding item.
Definition model_position.hpp:43
@ EMPTY
Successful content has zero logical rows.
Definition data_presentation.hpp:14
TextDocumentError
Finite document error; rejected operations preserve published state.
Definition text_document.hpp:88
@ STALE
Receipt belongs to another document or superseded save request.
Definition text_document.hpp:95
@ EXHAUSTED
A monotonic counter cannot advance.
Definition text_document.hpp:96
PositionResolution
Successful protocol outcomes; absence of support differs from missing history.
Definition model_position.hpp:123
@ UNAVAILABLE
Supported position history or storage is no longer available.
Definition model_position.hpp:130
@ INVALID_TEXT
Projected row is not admitted UTF-8 under the scene text policy.
Definition find_bar.hpp:53
@ NO_MEMORY
Allocation failed at a runner exception boundary.
Definition application.hpp:33
TextHistoryKind
Semantic editing categories; only the first three can form groups.
Definition text_history.hpp:38
@ WOULD_BLOCK
Active resume, invocation, registration or queue capacity rejects the operation.
Definition async.hpp:30
@ INVALID_ARGUMENT
Empty task, callback or immutable data owner, or invalid policy.
Definition async.hpp:26
@ CONFLICT
The model revision changed since this draft began.
Definition line_edit.hpp:86
SourceError
Source protocol and admission failures, independent of a provider's storage format.
Definition source_budget.hpp:14
@ NOT_BOUNDARY
A cursor offset is outside the text or inside a cluster.
Definition text.hpp:83
Explicit finite-buffer adapter configuration; not a windowed editor.
Definition text_document.hpp:109
TextHistoryOptions history
Existing bounded Undo/Redo; content tokens are enabled by this adapter.
Definition text_document.hpp:110
WidthPolicy widthPolicy
Existing Unicode/display validation policy.
Definition text_document.hpp:112
TextLimits limits
Existing finite whole-buffer admission limits.
Definition text_document.hpp:113
TextAnchorOptions anchors
Metadata proof capacity independent of text/history size.
Definition text_document.hpp:111
Owning scalar position; offset is meaningful only in the declared data revision.
Definition model_position.hpp:48
Logical resource namespace, distinct from its current delivery session. Reuse an existing SourceStamp...
Definition model_position.hpp:21
Owning resolution receipt; meaningful only for its matching live request.
Definition model_position.hpp:142
Immutable qualified navigation request; does not start work by itself.
Definition model_position.hpp:134
Immutable source namespace; replacement sessions must share their old budget root.
Definition window_source.hpp:27
Finite metadata retention, independent of logical document size.
Definition text_document.hpp:22
std::size_t maxChanges
Positive maximum retained splice edges and revision receipts.
Definition text_document.hpp:23
Configurable bounds and explicit-boundary grouping for text history.
Definition text_history.hpp:22
Owning limits checked without silently truncating input or clusters.
Definition text.hpp:57
Intermediate scalar mapping; not a boundary-validated PositionReply.
Definition text_document.hpp:27
PositionResolution state
Mapping proof outcome.
Definition text_document.hpp:28
ModelPosition position
Scalar hint requiring the provider's final grapheme-boundary validation.
Definition text_document.hpp:29
Byte-boundary selection owned by the document session, independent of a view.
Definition text_document.hpp:101
bool operator==(const TextSelection &other) const noexcept=default
std::size_t cursor
Active byte-boundary end.
Definition text_document.hpp:102
std::size_t anchor
Fixed byte-boundary end.
Definition text_document.hpp:103
Scalar text replacement proof; does not read or retain document bytes. Units are chosen by the enclos...
Definition text_document.hpp:15
std::uint64_t erased
Number of removed units.
Definition text_document.hpp:17
std::uint64_t inserted
Number of inserted units.
Definition text_document.hpp:18
std::uint64_t offset
First replaced scalar offset in the provider's text units.
Definition text_document.hpp:16
Owning deterministic width policy; no font or terminal matching promise.
Definition text.hpp:42