MCPcopy Index your code
hub / github.com/SplootCode/splootcode / replaceNode

Method replaceNode

packages/editor/src/context/selection.ts:421–441  ·  view source on GitHub ↗
(childSet: ChildSet, index: number, node: SplootNode)

Source from the content-addressed store, hash-verified

419 }
420
421 replaceNode(childSet: ChildSet, index: number, node: SplootNode) {
422 const nodeToReplace = childSet.getChild(index)
423 if (!isAdaptableToPasteDesintation(node, childSet.nodeCategory)) {
424 // Would the parent be empty without that node?
425 // Can we replace the parent instead?
426 const parentRef = nodeToReplace.parent
427 if (parentRef.node.childSetOrder.length === 1 && parentRef.getChildSet().getCount() === 1) {
428 const destCategory = parentRef.node.parent.getChildSet().nodeCategory
429 if (!isAdaptableToPasteDesintation(node, destCategory)) {
430 return false
431 }
432 childSet = parentRef.node.parent.getChildSet()
433 index = childSet.getIndexOf(parentRef.node)
434 } else {
435 return
436 }
437 }
438
439 childSet.removeChild(index)
440 this.insertNodeByChildSet(childSet, index, node)
441 }
442
443 insertFragment(fragment: SplootFragment, allowSingle = true) {
444 if (this.isCursor()) {

Callers 1

Calls 7

insertNodeByChildSetMethod · 0.95
getChildMethod · 0.80
getCountMethod · 0.80
getIndexOfMethod · 0.80
removeChildMethod · 0.80
getChildSetMethod · 0.45

Tested by

no test coverage detected