Donner 0.8.0-pre
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
SourceSelection.h File Reference
#include <cstddef>
#include <optional>
#include <span>
#include <string_view>
#include <vector>
#include "donner/base/EcsRegistry.h"
#include "donner/editor/TextEditor.h"
#include "donner/svg/SVGDocument.h"
#include "donner/svg/SVGElement.h"
Include dependency graph for SourceSelection.h:

Namespaces

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

Functions

bool donner::editor::HighlightElementSource (TextEditor &textEditor, const svg::SVGElement &element)
 Selects the source range for an SVG element in the text editor.
bool donner::editor::HighlightSourceByteRange (TextEditor &textEditor, SourceByteRange byteRange)
 Selects a raw source byte range in the text editor.
std::optional< SourceByteRangedonner::editor::EntitySourceByteRange (EntityHandle handle, std::string_view source)
 Return the serialized XML node byte range for an ECS entity.
std::optional< SourceByteRangedonner::editor::ElementSourceByteRange (const svg::SVGElement &element, std::string_view source)
 Return the serialized XML node byte range for an SVG element.
std::vector< svg::SVGElementdonner::editor::ExcludeSelectedSourceHoverElements (std::vector< svg::SVGElement > hoverElements, std::span< const svg::SVGElement > selectedElements)
 Removes elements already represented by the active editor selection from source-hover candidates.
std::vector< svg::SVGElementdonner::editor::ExcludeDocumentRootSourceHoverElement (std::vector< svg::SVGElement > hoverElements, const svg::SVGDocument &document)
 Removes the document root from automatic source-hover candidates.
std::optional< svg::SVGElementdonner::editor::FindElementAtSourceOffset (const svg::SVGDocument &document, std::string_view source, std::size_t offset)
 Finds the deepest SVG element whose source range contains offset.
std::optional< svg::SVGElementdonner::editor::FindElementNearSourceOffset (const svg::SVGDocument &document, std::string_view source, std::size_t offset)
 Finds the SVG element nearest a source caret-like offset.
std::optional< svg::SVGElementdonner::editor::FindElementAtSourceCursor (const svg::SVGDocument &document, const TextEditor &textEditor)
 Finds the deepest SVG element at the text editor cursor.

Function Documentation

◆ ElementSourceByteRange()

std::optional< SourceByteRange > donner::editor::ElementSourceByteRange ( const svg::SVGElement & element,
std::string_view source )

Return the serialized XML node byte range for an SVG element.

Parameters
elementSVG element whose source node should be resolved.
sourceSource text corresponding to the element's document.
Returns
Half-open byte range for the node, or std::nullopt if no source range exists.

◆ EntitySourceByteRange()

std::optional< SourceByteRange > donner::editor::EntitySourceByteRange ( EntityHandle handle,
std::string_view source )

Return the serialized XML node byte range for an ECS entity.

This is useful for resolved references where the caller has an EntityHandle but not a public svg::SVGElement wrapper.

Parameters
handleEntity whose XML node source should be resolved.
sourceSource text corresponding to the entity's document.
Returns
Half-open byte range for the node, or std::nullopt if no source range exists.

◆ ExcludeDocumentRootSourceHoverElement()

std::vector< svg::SVGElement > donner::editor::ExcludeDocumentRootSourceHoverElement ( std::vector< svg::SVGElement > hoverElements,
const svg::SVGDocument & document )

Removes the document root from automatic source-hover candidates.

The root <svg> source range covers the entire document, so automatic source hover should not turn that into a whole-canvas overlay preview.

Parameters
hoverElementsCandidate elements resolved from the source hover position.
documentDocument whose root should be excluded.
Returns
Hover candidates that are not the document root element.

◆ ExcludeSelectedSourceHoverElements()

std::vector< svg::SVGElement > donner::editor::ExcludeSelectedSourceHoverElements ( std::vector< svg::SVGElement > hoverElements,
std::span< const svg::SVGElement > selectedElements )

Removes elements already represented by the active editor selection from source-hover candidates.

Parameters
hoverElementsCandidate elements resolved from the source hover position.
selectedElementsActive editor selection.
Returns
Hover candidates that are not already selected.

◆ FindElementAtSourceCursor()

std::optional< svg::SVGElement > donner::editor::FindElementAtSourceCursor ( const svg::SVGDocument & document,
const TextEditor & textEditor )

Finds the deepest SVG element at the text editor cursor.

Parameters
documentSource-backed SVG document to inspect.
textEditorSource editor containing the cursor and source text.
Returns
Deepest SVG element at the cursor, or std::nullopt if none is found.

◆ FindElementAtSourceOffset()

std::optional< svg::SVGElement > donner::editor::FindElementAtSourceOffset ( const svg::SVGDocument & document,
std::string_view source,
std::size_t offset )

Finds the deepest SVG element whose source range contains offset.

Parameters
documentSource-backed SVG document to inspect.
sourceSource text corresponding to document.
offsetByte offset in source.
Returns
Deepest SVG element at offset, or std::nullopt if none is found.

◆ FindElementNearSourceOffset()

std::optional< svg::SVGElement > donner::editor::FindElementNearSourceOffset ( const svg::SVGDocument & document,
std::string_view source,
std::size_t offset )

Finds the SVG element nearest a source caret-like offset.

Unlike FindElementAtSourceOffset, this treats positions immediately after an opening or closing tag as still referring to that tag's element. This is useful for cursor and hover interactions where the UI position can land on the character cell after the source token.

Parameters
documentSource-backed SVG document to inspect.
sourceSource text corresponding to document.
offsetByte offset in source.
Returns
Best SVG element at or immediately before offset, or std::nullopt.

◆ HighlightElementSource()

bool donner::editor::HighlightElementSource ( TextEditor & textEditor,
const svg::SVGElement & element )

Selects the source range for an SVG element in the text editor.

Parameters
textEditorSource editor to update.
elementElement whose serialized XML node should be selected.
Returns
true if a source range was found and selected.

◆ HighlightSourceByteRange()

bool donner::editor::HighlightSourceByteRange ( TextEditor & textEditor,
SourceByteRange byteRange )

Selects a raw source byte range in the text editor.

Parameters
textEditorSource editor to update.
byteRangeHalf-open byte range to select.
Returns
true if the range was valid for the current text buffer.