set Context Node Id To Selection Ancestor
Type: Transform step
Set the contextNodeId
step data to the first matching element that is an ancestor of the cursor position.
This transform is commonly used in operations that are triggered from the toolbar, since those often respect the cursor position.
Use either selectionAncestorMatchesSomeOf
or selectionAncestorNodeSpec
, the first of which takes precedence over the other.
If an ancestor that matches any of the tests is not found, contextNodeId
is set to null.
Example:
Both examples are equivalent, but one uses selectionAncestorNodeSpec
where the other uses selectionAncestorMatchesSomeOf
.
Other
"insert-image": {
"label": "Insert image",
"steps": [
{
"type": "transform/setContextNodeIdToSelectionAncestor",
"data": {
"selectionAncestorNodeSpec": "self::section or self::div"
}
},
{
"type": "operation/vertical-insert",
"data": {
"childNodeStructure": ["img"]
}
}
]
}
Other
"insert-image": {
"label": "Insert image",
"steps": [
{
"type": "transform/setContextNodeIdToSelectionAncestor",
"data": {
"selectionAncestorMatchesSomeOf": [
"self::section",
"self::div"
]
}
},
{
"type": "operation/vertical-insert",
"data": {
"childNodeStructure": ["img"]
}
}
]
}
This makes the operation 'do-something' set stepData.contextNodeId to the first 'p' in the ancestry of the selectionRange
Imported operation data
Exported operation data
context
Node Id Type: NodeId