Skip to content

Commit 6772306

Browse files
authored
Fix: Correct path handling for dragged files on Windows (#2753)
1 parent b3065d2 commit 6772306

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

webview-ui/src/utils/path-mentions.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@
1313
*/
1414
export function convertToMentionPath(path: string, cwd?: string): string {
1515
// Strip file:// protocol if present
16-
const pathWithoutProtocol = path.startsWith("file://") ? path.substring(7) : path
16+
let pathWithoutProtocol = path.startsWith("file://") ? path.substring(7) : path
17+
18+
try {
19+
pathWithoutProtocol = decodeURIComponent(pathWithoutProtocol)
20+
// Fix: Remove leading slash for Windows paths like /d:/...
21+
if (pathWithoutProtocol.startsWith("/") && pathWithoutProtocol[2] === ":") {
22+
pathWithoutProtocol = pathWithoutProtocol.substring(1)
23+
}
24+
} catch (e) {
25+
// Log error if decoding fails, but continue with the potentially problematic path
26+
console.error("Error decoding URI component in convertToMentionPath:", e, pathWithoutProtocol)
27+
}
1728

1829
const normalizedPath = pathWithoutProtocol.replace(/\\/g, "/")
1930
let normalizedCwd = cwd ? cwd.replace(/\\/g, "/") : ""

0 commit comments

Comments
 (0)