MCPcopy Create free account
hub / github.com/Easy-Editor/EasyEditor / replaceChild

Method replaceChild

packages/core/src/document/node/node.ts:633–653  ·  view source on GitHub ↗

* replace a child node with a new node

(node: Node, data: Schema)

Source from the content-addressed store, hash-verified

631 * replace a child node with a new node
632 */
633 replaceChild(node: Node, data: Schema): Node | null {
634 if (this.children?.has(node)) {
635 const selected = this.document.designer.selection.has(node.id)
636
637 data.id = undefined
638 const newNode = this.document.createNode(data)
639
640 if (!isNode(newNode)) {
641 return null
642 }
643
644 this.insertBefore(newNode, node, false)
645 node.remove(false)
646
647 if (selected) {
648 this.document.designer.selection.select(newNode.id)
649 }
650 return newNode
651 }
652 return node
653 }
654
655 /**
656 * check if this node contains another node

Callers 1

replaceWithMethod · 0.80

Calls 6

insertBeforeMethod · 0.95
isNodeFunction · 0.85
createNodeMethod · 0.80
hasMethod · 0.65
removeMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected