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

Classifies a text edit as either an attribute-value change on a specific element (fast path → SetAttributeCommand) or a structural change (fallback → ReplaceDocumentCommand). This is the M5 gate: when structured editing is enabled, the main loop calls classifyTextChange instead of unconditionally emitting a ReplaceDocumentCommand. More...

#include <optional>
#include <string_view>
#include "donner/editor/EditorCommand.h"
#include "donner/svg/SVGDocument.h"
Include dependency graph for ChangeClassifier.h:

Classes

struct  donner::editor::ClassifyResult
 Result of classifying a text change. More...

Namespaces

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

Functions

ClassifyResult donner::editor::classifyTextChange (svg::SVGDocument &document, std::string_view oldSource, std::string_view newSource)
 Try to classify a text change as an in-attribute-value edit.

Detailed Description

Classifies a text edit as either an attribute-value change on a specific element (fast path → SetAttributeCommand) or a structural change (fallback → ReplaceDocumentCommand). This is the M5 gate: when structured editing is enabled, the main loop calls classifyTextChange instead of unconditionally emitting a ReplaceDocumentCommand.

The classifier is deliberately conservative — any edit it can't conclusively identify as an in-attribute-value change falls through to the structural-fallback path, which re-parses the entire document.

Function Documentation

◆ classifyTextChange()

ClassifyResult donner::editor::classifyTextChange ( svg::SVGDocument & document,
std::string_view oldSource,
std::string_view newSource )

Try to classify a text change as an in-attribute-value edit.

Compares oldSource and newSource to find the changed byte range, then checks whether that range falls entirely inside a single quoted attribute value on a single element. If so, returns a SetAttributeCommand for that element and attribute. Otherwise returns an empty ClassifyResult (structural fallback).

Parameters
documentThe current SVG document (used to find elements by source offset).
oldSourceThe source text before the edit.
newSourceThe source text after the edit.
Returns
Classification result — either a SetAttributeCommand or std::nullopt for structural fallback.