MCPcopy
hub / github.com/markmap/markmap / findActiveNode

Function findActiveNode

packages/markmap-cli/src/client/index.ts:61–91  ·  view source on GitHub ↗
({
  line,
  autoExpand = true,
}: {
  line: number;
  autoExpand?: boolean;
})

Source from the content-addressed store, hash-verified

59}
60
61function findActiveNode({
62 line,
63 autoExpand = true,
64}: {
65 line: number;
66 autoExpand?: boolean;
67}) {
68 function dfs(node: INode, ancestors: INode[] = []) {
69 const [start, end] =
70 (node.payload?.lines as string)?.split(',').map((s) => +s) || [];
71 if (start >= 0 && start <= line && line < end) {
72 best = node;
73 bestAncestors = ancestors;
74 }
75 ancestors = [...ancestors, node];
76 node.children?.forEach((child) => {
77 dfs(child, ancestors);
78 });
79 }
80 let best: INode | undefined;
81 let bestAncestors: INode[] = [];
82 dfs((state.content.value as ITransformResult).root as INode);
83 if (autoExpand) {
84 bestAncestors.forEach((node) => {
85 if (node.payload?.fold) {
86 node.payload.fold = 0;
87 }
88 });
89 }
90 return best;
91}
92
93async function setCursor(options: { line: number; autoExpand?: boolean }) {
94 if (!state.content.value) return;

Callers 1

setCursorFunction · 0.85

Calls 1

dfsFunction · 0.85

Tested by

no test coverage detected