|
|
Donner 0.5.1
Embeddable browser-grade SVG2 engine
|
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"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. | |
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.
| 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).
| document | The current SVG document (used to find elements by source offset). |
| oldSource | The source text before the edit. |
| newSource | The source text after the edit. |