Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
Loading...
Searching...
No Matches
donner::editor::EditorCommand Struct Reference

Discriminated union of every editor-initiated DOM mutation in the M2 scope. Coalescing rules in CommandQueue are keyed off kind plus the command's payload. More...

#include "donner/editor/EditorCommand.h"

Public Types

enum class  Kind : std::uint8_t {
  SetTransform ,
  ReplaceDocument ,
  SetAttribute ,
  RemoveAttribute ,
  InsertElement ,
  DeleteElement ,
  CutShapes ,
  PasteShapes ,
  InsertText ,
  SetTextContent
}

Static Public Member Functions

static EditorCommand SetTransformCommand (svg::SVGElement element, const Transform2d &transform)
 Builds a SetTransform command.
static EditorCommand ReplaceDocumentCommand (std::string bytes, bool preserveUndoOnReparse=false)
 Builds a ReplaceDocument command from owned bytes.
static EditorCommand SetAttributeCommand (svg::SVGElement element, std::string name, std::string value)
 Builds a SetAttribute command.
static EditorCommand RemoveAttributeCommand (svg::SVGElement element, std::string name)
 Builds a RemoveAttribute command (DOM-level attribute removal).
static EditorCommand InsertElementCommand (svg::SVGElement parent, svg::SVGElement element, std::optional< svg::SVGElement > reference=std::nullopt)
 Builds an InsertElement command.
static EditorCommand DeleteElementCommand (svg::SVGElement element)
 Builds a DeleteElement command.
static EditorCommand CutShapesCommand (std::string bytes)
 Builds a CutShapes command from the post-cut source bytes. The caller is responsible for recording the matching undo entry on the timeline; the command itself just swaps the document.
static EditorCommand PasteShapesCommand (std::string bytes)
 Builds a PasteShapes command from the post-paste source bytes.
static EditorCommand InsertTextCommand (svg::SVGElement parent, svg::SVGElement textElement, std::string content, std::optional< svg::SVGElement > reference=std::nullopt)
 Builds an InsertText command. textElement should be a freshly-created <text> element; its text content is set to content when applied.
static EditorCommand SetTextContentCommand (svg::SVGElement element, std::string content)
 Builds a SetTextContent command.

Public Attributes

Kind kind = Kind::SetTransform
std::optional< svg::SVGElementelement
 Target element for SetTransform and DeleteElement. std::nullopt for ReplaceDocument.
std::optional< svg::SVGElementparentElement
 Parent element for InsertElement.
std::optional< svg::SVGElementreferenceElement
 Optional sibling for InsertElement; inserted before this element when present, otherwise appended to the parent.
Transform2d transform
 SetTransform payload. Default-constructed for ReplaceDocument / DeleteElement.
std::string bytes
 ReplaceDocument payload. Empty for SetTransform / DeleteElement. Stored by value because the source buffer (TextEditor or file contents) may go out of scope before the queue flushes.
bool preserveUndoOnReparse = false
 ReplaceDocument payload: preserve the undo timeline if this reparse is the only ReplaceDocument in the flushed batch. Used by the editor's self-initiated source writeback path, which reparses to refresh XML source offsets without representing a new user-authored document baseline.
std::string attributeName
 SetAttribute payload: the attribute name (e.g. "transform", "fill").
std::string attributeValue
 SetAttribute payload: the new attribute value.
std::string textContent
 InsertText / SetTextContent payload: the text content to apply. Stored by value because the source string (default content or inspector buffer) may go out of scope before the queue flushes.

Detailed Description

Discriminated union of every editor-initiated DOM mutation in the M2 scope. Coalescing rules in CommandQueue are keyed off kind plus the command's payload.

Commands carry svg::SVGElement handles rather than raw ECS entities so the editor never has to touch the registry directly - every payload value comes from a public SVG-level API (EditorApp::hitTest, tree traversal, querySelector) and every applied mutation goes through public SVGElement / SVGGraphicsElement methods.

Member Enumeration Documentation

◆ Kind

enum class donner::editor::EditorCommand::Kind : std::uint8_t
strong
Enumerator
SetTransform 

Set the element's transform attribute. Used by SelectTool drag and undo/redo replay. Coalesces by element identity at flush time - multiple SetTransform commands targeting the same element collapse into the most-recently-queued one.

ReplaceDocument 

Replace the entire document by re-parsing the given bytes. Used by file load and by the text-editor pane's typing → full-regen path. Exclusive: drains the queue of every prior command (which would reference now-invalid elements).

SetAttribute 

Set a single attribute on the element. Used by the structured- editing writeback path (M3) when a tool modifies an attribute value. Coalesces by (element, attributeName) - successive SetAttribute commands for the same element and attribute collapse to the most-recently-queued value.

RemoveAttribute 

Remove a single attribute from the element (DOM-level). Used to clear a marker attribute rather than leaving a falsy value behind - e.g. unlocking a layer removes data-donner-locked instead of writing ="false". No-op if the attribute is absent. Not coalesced.

InsertElement 

Insert element as a child of parentElement, optionally before referenceElement. Used by authoring tools that create new DOM nodes. Not coalesced.

DeleteElement 

Detach the element from its parent, making it invisible to the renderer. The ECS entity itself is NOT destroyed - it stays in the registry, just orphaned. This is a "soft delete" so any in-flight references (stale selection, undo snapshots) stay valid. Not coalesced.

CutShapes 

Replace the entire document by reparsing the post-cut bytes for a shape-clipboard Cut. Behaves like ReplaceDocument with preserveUndoOnReparse=true, but tags the operation so undo / telemetry can label it "Cut shapes" instead of a generic reparse. Exclusive: drains the queue of every prior command. See donner/editor/ShapeClipboardCommands.h.

PasteShapes 

Replace the entire document by reparsing the post-paste bytes for a shape-clipboard Paste / Paste in Front. Behaves like ReplaceDocument with preserveUndoOnReparse=true, but tags the operation so undo / telemetry can label it "Paste shapes". Exclusive: drains the queue of every prior command. See donner/editor/ShapeClipboardCommands.h.

InsertText 

Insert a <text> element carrying textContent as a child of parentElement, optionally before referenceElement. Used by the Text authoring tool (TextTool). The element's text content is set from textContent and the element is then attached exactly like InsertElement. Not coalesced.

SetTextContent 

Replace the element's text content with textContent (the element is a <text> or <tspan>). Used by the text-property inspector's content field. Coalesces by element identity at flush time - successive SetTextContent commands targeting the same element collapse to the most-recently-queued value, like SetTransform.


The documentation for this struct was generated from the following file: