MCPcopy Index your code
hub / github.com/codeaashu/claude-code / insertBeforeNode

Function insertBeforeNode

src/ink/dom.ts:155–202  ·  view source on GitHub ↗
(
  node: DOMElement,
  newChildNode: DOMNode,
  beforeChildNode: DOMNode,
)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

removeChildNodeFunction · 0.85
markDirtyFunction · 0.85
spliceMethod · 0.80
insertChildMethod · 0.45
pushMethod · 0.45
getChildCountMethod · 0.45

Tested by

no test coverage detected