mergeStructure

Type: Function

Merges a new structure into the current structure, reusing as little of the old structure as possible

Example working use case: there may or may not exist an existing element A, Z and X under the root, which may or may not have an element B, optionally containing a C.

  • We want to reuse A, or make it

  • We want to reuse B, or make it

  • We want to make a new C, always

  • We want our new content to appear in the new element C

This way, we will not depend on the precise contentmodel of any of the elements.

Other

  Current   * Provided context                              *  Provided new structure
  structure *                                               *
 ---------- * ------------ | ------------------------------ * -------------|--------------------------
     O      *       O      | The root of the merge          * newC.end:    | Add the new C at
     |      *       |      |                                *              |  the end of the newC gap
     A      *  <.*> A <.*> | Gaps, because Z or X may exist *     C        | Create a C
     |      *       |      |                                *     |        |
     B      *       B      | No gap, to enforce reuse       * 'new text'   | With some contents
     |      *       |      |                                *              |
     C      *   <newC:.*>  | Gap, to allow an existing C    *              |
     |      *              |                                *              |
'old text'  *              |                                *              |

The following will be done:

Other

                 O
                 |
                 A
                 |
                 B
                 |
                 C
                 |
 <newC.start> 'oldText' <newC.end>

Because the substructure for newC.end is provided, it will be inserted at the newC.end position, making the following structure:

Other

         O
         |
         A
         |
         B
       /   \
      C     C
     /       \
'old text'  'new text'

Note: It is also very much possible to provide a non-position gap, this way, multiple positions will be considered. The first position allowing insert wins.

Refer to primitives for more information on how to include this primitive.

Arguments

  1. rootNode

    (Required)

    Type: Node

  2. contextStencil

    (Required)

    Type: Stencil

  3. subStructuresByGapId

    (Required)

    Type: Object<String, Stencil>

  4. blueprint

    (Required)

    Type: Blueprint

  5. format

    (Required)

    Type: Format

  6. selectionRange

    (Required)

Returns

Type: Boolean