setContextNodeIdToSelectionAncestor

How to get setContextNodeIdToSelectionAncestor

Depend on fontoxml-base-flow to make this transform available.

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.

"insert-image": {
  "label": "Insert image",
   "steps": [
     {
       "type": "transform/setContextNodeIdToSelectionAncestor",
       "data": {
         "selectionAncestorNodeSpec": "self::section or self::div"
       }
     },
     {
       "type": "operation/vertical-insert",
       "data": {
         "childNodeStructure": ["img"]
       }
     }
   ]
}
"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

Name Type Description
selectionAncestorMatchesSomeOf Array<XPathTest>

An array of XPath tests, similar to selectionAncestorNodeSpec but more readable if you have many different tests.

[selectionAncestorNodeSpec] XPathTest

An XPath test to which the result context node must assert true.

Exported operation data

Name Type Description
contextNodeId NodeId
Was this page helpful?