MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / insertBeforeNode

Function insertBeforeNode

source code/ink/dom.ts:157–204  ·  view source on GitHub ↗
(
  node: DOMElement,
  newChildNode: DOMNode,
  beforeChildNode: DOMNode,
)

Source from the content-addressed store, hash-verified

155}
156
157export const insertBeforeNode = (
158 node: DOMElement,
159 newChildNode: DOMNode,
160 beforeChildNode: DOMNode,
161): void => {
162 if (newChildNode.parentNode) {
163 removeChildNode(newChildNode.parentNode, newChildNode)
164 }
165
166 newChildNode.parentNode = node
167
168 const index = node.childNodes.indexOf(beforeChildNode)
169
170 if (index >= 0) {
171 // Calculate yoga index BEFORE modifying childNodes.
172 // We can't use DOM index directly because some children (like ink-progress,
173 // ink-link, ink-virtual-text) don't have yogaNodes, so DOM indices don't
174 // match yoga indices.
175 let yogaIndex = 0
176 if (newChildNode.yogaNode && node.yogaNode) {
177 for (let i = 0; i < index; i++) {
178 if (node.childNodes[i]?.yogaNode) {
179 yogaIndex++
180 }
181 }
182 }
183
184 node.childNodes.splice(index, 0, newChildNode)
185
186 if (newChildNode.yogaNode && node.yogaNode) {
187 node.yogaNode.insertChild(newChildNode.yogaNode, yogaIndex)
188 }
189
190 markDirty(node)
191 return
192 }
193
194 node.childNodes.push(newChildNode)
195
196 if (newChildNode.yogaNode) {
197 node.yogaNode?.insertChild(
198 newChildNode.yogaNode,
199 node.yogaNode.getChildCount(),
200 )
201 }
202
203 markDirty(node)
204}
205
206export const removeChildNode = (
207 node: DOMElement,

Callers

nothing calls this directly

Calls 4

removeChildNodeFunction · 0.85
markDirtyFunction · 0.85
insertChildMethod · 0.45
getChildCountMethod · 0.45

Tested by

no test coverage detected