MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / getTreeLinePrefix

Function getTreeLinePrefix

packages/core/src/widgets/tree.ts:171–205  ·  view source on GitHub ↗
(
  flatNode: FlattenedNode<T>,
  showLines: boolean,
  indentSize: number,
)

Source from the content-addressed store, hash-verified

169 * @returns String prefix for the node
170 */
171export function getTreeLinePrefix<T>(
172 flatNode: FlattenedNode<T>,
173 showLines: boolean,
174 indentSize: number,
175): string {
176 if (flatNode.depth === 0) {
177 return "";
178 }
179
180 if (!showLines) {
181 // Simple indentation without lines
182 return " ".repeat(flatNode.depth * indentSize);
183 }
184
185 // Build tree line prefix
186 const parts: string[] = [];
187
188 // Add ancestor lines (excluding the last which is for current node)
189 for (let i = 0; i < flatNode.depth - 1; i++) {
190 const isLast = flatNode.ancestorIsLast[i];
191 if (isLast) {
192 // Ancestor was last child, no continuing line
193 parts.push(TREE_CHARS.space);
194 } else {
195 // Ancestor has siblings below, show continuing line
196 parts.push(`${TREE_CHARS.vertical} `);
197 }
198 }
199
200 // Add branch for current node
201 const isLast = flatNode.siblingIndex === flatNode.siblingCount - 1;
202 parts.push(isLast ? TREE_CHARS.lastBranch : TREE_CHARS.branch);
203
204 return parts.join("");
205}
206
207/* ========== Navigation ========== */
208

Callers 3

getTreePrefixesFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected