From 6772306ade0aa93d6905667a0bf92c57525f9f2c Mon Sep 17 00:00:00 2001 From: Felix NyxJae <52313587+NyxJae@users.noreply.github.com> Date: Fri, 18 Apr 2025 22:29:32 +0800 Subject: [PATCH] Fix: Correct path handling for dragged files on Windows (#2753) --- webview-ui/src/utils/path-mentions.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/webview-ui/src/utils/path-mentions.ts b/webview-ui/src/utils/path-mentions.ts index 3021fe5069..1afa76156a 100644 --- a/webview-ui/src/utils/path-mentions.ts +++ b/webview-ui/src/utils/path-mentions.ts @@ -13,7 +13,18 @@ */ export function convertToMentionPath(path: string, cwd?: string): string { // Strip file:// protocol if present - const pathWithoutProtocol = path.startsWith("file://") ? path.substring(7) : path + let pathWithoutProtocol = path.startsWith("file://") ? path.substring(7) : path + + try { + pathWithoutProtocol = decodeURIComponent(pathWithoutProtocol) + // Fix: Remove leading slash for Windows paths like /d:/... + if (pathWithoutProtocol.startsWith("/") && pathWithoutProtocol[2] === ":") { + pathWithoutProtocol = pathWithoutProtocol.substring(1) + } + } catch (e) { + // Log error if decoding fails, but continue with the potentially problematic path + console.error("Error decoding URI component in convertToMentionPath:", e, pathWithoutProtocol) + } const normalizedPath = pathWithoutProtocol.replace(/\\/g, "/") let normalizedCwd = cwd ? cwd.replace(/\\/g, "/") : ""