private updateOuterEditor()

in src/plugin/fieldViews/ProseMirrorFieldView.ts [268:318]


  private updateOuterEditor(
    innerTr: Transaction,
    innerState: EditorState,
    transactions: readonly Transaction[]
  ) {
    const outerTr = this.outerView.state.tr;
    // When we insert content, we must offset to account for a few things:
    //  - getPos() returns the position directly before the parent node (+1)
    //  - the node we will be altering is a child of its parent (+1)
    const contentOffset = 2;
    const offsetMap = StepMap.offset(
      this.getPos() + this.offset + contentOffset
    );
    for (let i = 0; i < transactions.length; i++) {
      const steps = transactions[i].steps;
      for (let j = 0; j < steps.length; j++) {
        const mappedStep = steps[j].map(offsetMap);
        if (mappedStep) {
          outerTr.step(mappedStep);
        }
      }
    }

    const selection = innerState.selection;
    const mappedSelection = selection.map(outerTr.doc, offsetMap);

    const selectionHasChanged = !outerTr.selection.eq(mappedSelection);
    if (selectionHasChanged) {
      outerTr.setSelection(mappedSelection);
    }

    if (innerTr.getMeta("paste") === true) {
      // Pass the "paste" meta specifically, because we know it's needed by
      // another plugin to handle pastes - meta values won't be transferred
      // to the outerTr unless we set them.
      outerTr.setMeta("paste", true);
    }

    const storedMarksHaveChanged = !isEqual(
      this.outerView.state.storedMarks,
      innerTr.storedMarks
    );

    if (storedMarksHaveChanged) {
      outerTr.setStoredMarks(innerTr.storedMarks);
    }

    const shouldUpdateOuter =
      innerTr.docChanged || selectionHasChanged || storedMarksHaveChanged;
    if (shouldUpdateOuter) this.dispatchToOuterView(outerTr);
  }