From e96a9bb5ca0141a3732d73c858f15516b354f9c8 Mon Sep 17 00:00:00 2001 From: Felix NyxJae <18661811993@163.com> Date: Fri, 18 Apr 2025 16:58:12 +0800 Subject: [PATCH 1/2] Fix: Correct path handling for dragged files on Windows --- 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, "/") : "" From 41864031ab5f21e8bfe1858a23677ac8b085be3c Mon Sep 17 00:00:00 2001 From: Felix NyxJae <18661811993@163.com> Date: Mon, 21 Apr 2025 16:01:17 +0800 Subject: [PATCH 2/2] Fix: Improve drag-and-drop and SSH path handling --- webview-ui/src/components/chat/ChatTextArea.tsx | 5 ++++- webview-ui/src/utils/path-mentions.ts | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/webview-ui/src/components/chat/ChatTextArea.tsx b/webview-ui/src/components/chat/ChatTextArea.tsx index 369ae5e721..9cfeddd5ea 100644 --- a/webview-ui/src/components/chat/ChatTextArea.tsx +++ b/webview-ui/src/components/chat/ChatTextArea.tsx @@ -614,7 +614,10 @@ const ChatTextArea = forwardRef( e.preventDefault() setIsDraggingOver(false) - const text = e.dataTransfer.getData("application/vnd.code.uri-list") + const textFieldList = e.dataTransfer.getData("text") + const textUriList = e.dataTransfer.getData("application/vnd.code.uri-list") + // When textFieldList is empty, it may attempt to use textUriList obtained from drag-and-drop tabs; if not empty, it will use textFieldList. + const text = textFieldList || textUriList if (text) { // Split text on newlines to handle multiple files const lines = text.split(/\r?\n/).filter((line) => line.trim() !== "") diff --git a/webview-ui/src/utils/path-mentions.ts b/webview-ui/src/utils/path-mentions.ts index 1afa76156a..3a499688d6 100644 --- a/webview-ui/src/utils/path-mentions.ts +++ b/webview-ui/src/utils/path-mentions.ts @@ -12,8 +12,20 @@ * @returns A mention-friendly path */ export function convertToMentionPath(path: string, cwd?: string): string { - // Strip file:// protocol if present - let pathWithoutProtocol = path.startsWith("file://") ? path.substring(7) : path + // Strip file:// or vscode-remote:// protocol if present + let pathWithoutProtocol = path + + if (path.startsWith("file://")) { + pathWithoutProtocol = path.substring(7) + } else if (path.startsWith("vscode-remote://")) { + const protocolStripped = path.substring("vscode-remote://".length) + const firstSlashIndex = protocolStripped.indexOf("/") + if (firstSlashIndex !== -1) { + pathWithoutProtocol = protocolStripped.substring(firstSlashIndex + 1) + } else { + pathWithoutProtocol = "" + } + } try { pathWithoutProtocol = decodeURIComponent(pathWithoutProtocol)