Repository: ianstormtaylor/slate
File: packages/slate/src/transforms/node.ts (TypeScript)

Code before:
    } = {}
  ): void {
    Editor.withoutNormalizing(editor, () => {
      const { mode = 'lowest', split = false, voids = false } = options
      let { at = editor.selection, match } = options

      if (!at) {
        return
      }

      if (match == null) {
        match = Path.isPath(at)
          ? matchPath(editor, at)
          : n => Editor.isBlock(editor, n)
      }

      if (Path.isPath(at)) {
        at = Editor.range(editor, at)
      }

      const rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null
      const matches = Editor.nodes(editor, { at, match, mode, voids })
      const pathRefs = Array.from(
        matches,
        ([, p]) => Editor.pathRef(editor, p)
        // unwrapNode will call liftNode which does not support splitting the mode when nested.
        // If we do not reverse the order and call it from top to the bottom, it will remove all blocks
        // that wrap target node. So we reverse the order.
      ).reverse()

      for (const pathRef of pathRefs) {
        const path = pathRef.unref()!
        const [node] = Editor.node(editor, path)
        let range = Editor.range(editor, path)

        if (split && rangeRef) {
          range = Range.intersection(rangeRef.current!, range)!
        }

        Transforms.liftNodes(editor, {
          at: range,
          match: n => Element.isAncestor(node) && node.children.includes(n),
          voids,
        })
      }

      if (rangeRef) {
        rangeRef.unref()
      }
    })
  },

Review comment (suggestion):
```suggestion
        // unwrapNode will call liftNode which does not support splitting the node when nested.
```

Code after:
    } = {}
  ): void {
    Editor.withoutNormalizing(editor, () => {
      const { mode = 'lowest', split = false, voids = false } = options
      let { at = editor.selection, match } = options

      if (!at) {
        return
      }

      if (match == null) {
        match = Path.isPath(at)
          ? matchPath(editor, at)
          : n => Editor.isBlock(editor, n)
      }

      if (Path.isPath(at)) {
        at = Editor.range(editor, at)
      }

      const rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null
      const matches = Editor.nodes(editor, { at, match, mode, voids })
      const pathRefs = Array.from(
        matches,
        ([, p]) => Editor.pathRef(editor, p)
        // unwrapNode will call liftNode which does not support splitting the node when nested.
        // If we do not reverse the order and call it from top to the bottom, it will remove all blocks
        // that wrap target node. So we reverse the order.
      ).reverse()

      for (const pathRef of pathRefs) {
        const path = pathRef.unref()!
        const [node] = Editor.node(editor, path)
        let range = Editor.range(editor, path)

        if (split && rangeRef) {
          range = Range.intersection(rangeRef.current!, range)!
        }

        Transforms.liftNodes(editor, {
          at: range,
          match: n => Element.isAncestor(node) && node.children.includes(n),
          voids,
        })
      }

      if (rangeRef) {
        rangeRef.unref()
      }
    })
  },