Donner 0.5.1
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
TextPatch.h File Reference

The TextPatch type and applyPatches function form the editor's canvas-to-text writeback sideband. When a tool mutates an attribute via EditorApp::applyMutation, it also produces a TextPatch that describes the corresponding byte-level splice in the source text. The main loop drains pending patches after flushFrame() and before rendering the source pane. More...

#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
#include <vector>
Include dependency graph for TextPatch.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::editor::TextPatch
 A byte-level splice in the source text buffer. More...
struct  donner::editor::ApplyPatchesResult
 Result of an applyPatches call. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

ApplyPatchesResult donner::editor::applyPatches (std::string &source, std::span< const TextPatch > patches)
 Apply a batch of TextPatch values to a source string.

Detailed Description

The TextPatch type and applyPatches function form the editor's canvas-to-text writeback sideband. When a tool mutates an attribute via EditorApp::applyMutation, it also produces a TextPatch that describes the corresponding byte-level splice in the source text. The main loop drains pending patches after flushFrame() and before rendering the source pane.

See docs/design_docs/structured_text_editing.md M3 for the full design.

Function Documentation

◆ applyPatches()

ApplyPatchesResult donner::editor::applyPatches ( std::string & source,
std::span< const TextPatch > patches )

Apply a batch of TextPatch values to a source string.

Patches are sorted by descending offset before application so each splice doesn't shift the byte offsets of subsequent patches. Patches that would read past the end of the current string are rejected (counted in result.rejectedBounds). The remaining patches are applied in place.

Parameters
sourceThe mutable source text. Modified in place.
patchesThe patches to apply. Order does not matter — the function sorts internally.
Returns
Summary of how many patches were applied vs. rejected.