From fb16f2eba21d37b744d3292deba641d2f5e8ac74 Mon Sep 17 00:00:00 2001 From: Rohit Lahu Bhalekar <165887184+DevROHIT11@users.noreply.github.com> Date: Wed, 8 Apr 2026 21:54:57 +0530 Subject: [PATCH] Fix YAML node highlight path resolution --- src/components/MonacoEditor.tsx | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/components/MonacoEditor.tsx b/src/components/MonacoEditor.tsx index 95ae928..0a2a92b 100644 --- a/src/components/MonacoEditor.tsx +++ b/src/components/MonacoEditor.tsx @@ -173,8 +173,8 @@ const MonacoEditor = () => { .filter((segment: string) => segment !== "") .map((segment: string) => decodePointerSegment(segment)); - const buildPathCandidates = (segments: string[]) => { - return segments.reduce>>( + const buildPathCandidates = (segments: string[]) => + segments.reduce>>( (candidates, segment) => { if (!/^\d+$/.test(segment)) { return candidates.map((candidate) => [...candidate, segment]); @@ -188,34 +188,14 @@ const MonacoEditor = () => { }, [[]] ); - const getTypedPath = (segments: string[], parsedRoot: unknown) => { - const typedSegments: Array = []; - let current: any = parsedRoot; - - for (const segment of segments) { - const isArrayIndex = Array.isArray(current) && /^\d+$/.test(segment); - const pathSegment: string | number = isArrayIndex - ? parseInt(segment, 10) - : segment; - - typedSegments.push(pathSegment); - current = current?.[pathSegment as keyof typeof current]; - } - - return typedSegments; - }; let startPos, endPos; try { const pathCandidates = buildPathCandidates(rawPath); - const parsedRoot = - schemaFormat === "yaml" ? YAML.load(text) : JSON.parse(text); - const typedPath = getTypedPath(rawPath, parsedRoot); if (schemaFormat === "yaml") { const doc = parseDocument(text); - // If path is empty, we are at root, otherwise fetch the node. const node = (rawPath.length === 0 ? doc.contents : pathCandidates @@ -226,9 +206,6 @@ const MonacoEditor = () => { typeof candidateNode === "object" && "range" in candidateNode )) as any; - const node = (typedPath.length === 0 - ? doc.contents - : doc.getIn(typedPath, true)) as any; if (!node || !node.range) return; @@ -242,7 +219,6 @@ const MonacoEditor = () => { const node = pathCandidates .map((candidatePath) => findNodeAtLocation(tree, candidatePath)) .find((candidateNode) => !!candidateNode); - const node = findNodeAtLocation(tree, typedPath); if (!node) return; startPos = model.getPositionAt(node.offset);