Skip to content

Commit c4851f0

Browse files
nrjdalalclaude
andcommitted
fix: resolve relative symlink paths for folder jump and target selection
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3282af2 commit c4851f0

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

bin/utils/interactive-picker.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ function setSelected(node: TreeNode, value: boolean) {
136136
}
137137
}
138138

139+
function resolveSymlinkPath(symlinkPath: string, linkTarget: string): string {
140+
const symlinkDir = symlinkPath.includes("/") ? symlinkPath.split("/").slice(0, -1).join("/") : ""
141+
const rawTarget = linkTarget.replace(/\/$/, "")
142+
const resolved = symlinkDir ? `${symlinkDir}/${rawTarget}` : rawTarget
143+
const parts = resolved.split("/")
144+
const normalized: string[] = []
145+
for (const p of parts) {
146+
if (p === "..") normalized.pop()
147+
else if (p !== ".") normalized.push(p)
148+
}
149+
return normalized.join("/")
150+
}
151+
139152
function findNodeByPath(roots: TreeNode[], targetPath: string): TreeNode | null {
140153
for (const node of roots) {
141154
if (node.path === targetPath) return node
@@ -553,7 +566,7 @@ export function interactivePicker(
553566
setSelected(item.node, newValue)
554567
// If symlink selected, also select the target (but don't deselect it)
555568
if (newValue && item.node.type === "symlink" && item.node.linkTarget) {
556-
const targetPath = item.node.linkTarget.replace(/\/$/, "")
569+
const targetPath = resolveSymlinkPath(item.node.path, item.node.linkTarget)
557570
const targetNode = findNodeByPath(tree, targetPath)
558571
if (targetNode) setSelected(targetNode, true)
559572
}
@@ -567,8 +580,8 @@ export function interactivePicker(
567580
if (item && item.node.type === "tree") {
568581
item.node.expanded = !item.node.expanded
569582
} else if (item && item.node.type === "symlink" && item.node.linkTarget.endsWith("/")) {
570-
// Symlink to folder - jump to target and expand it
571-
const targetPath = item.node.linkTarget.replace(/\/$/, "")
583+
// Symlink to folder - resolve relative path and jump to target
584+
const targetPath = resolveSymlinkPath(item.node.path, item.node.linkTarget)
572585
const targetNode = findNodeByPath(tree, targetPath)
573586
if (targetNode) {
574587
targetNode.expanded = true

0 commit comments

Comments
 (0)