setContextNodeIdToSelectionAncestor

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

  1. selectionAncestorMatchesSomeOf

    Type: Array<XPathTest>

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

  2. selectionAncestorNodeSpec

    Type: XPathTest

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

Exported operation data

  1. contextNodeId

    Type: NodeId