diff --git a/webview-ui/src/components/chat/ChatTextArea.tsx b/webview-ui/src/components/chat/ChatTextArea.tsx index 97cf28b269..84bc7634e2 100644 --- a/webview-ui/src/components/chat/ChatTextArea.tsx +++ b/webview-ui/src/components/chat/ChatTextArea.tsx @@ -612,7 +612,7 @@ const ChatTextArea = forwardRef( e.preventDefault() setIsDraggingOver(false) - const text = e.dataTransfer.getData("text") + const text = e.dataTransfer.getData("application/vnd.code.uri-list") 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/__tests__/path-mentions.test.ts b/webview-ui/src/utils/__tests__/path-mentions.test.ts index bb5591fbe5..e0f291b7f6 100644 --- a/webview-ui/src/utils/__tests__/path-mentions.test.ts +++ b/webview-ui/src/utils/__tests__/path-mentions.test.ts @@ -41,5 +41,20 @@ describe("path-mentions", () => { "@/nested/deeply/file.txt", ) }) + + it("should strip file:// protocol from paths if present", () => { + // Without cwd + expect(convertToMentionPath("file:///Users/user/project/file.txt")).toBe("/Users/user/project/file.txt") + + // With cwd - should strip protocol and then apply mention path logic + expect(convertToMentionPath("file:///Users/user/project/file.txt", "/Users/user/project")).toBe( + "@/file.txt", + ) + + // With Windows paths + expect(convertToMentionPath("file://C:/Users/user/project/file.txt", "C:/Users/user/project")).toBe( + "@/file.txt", + ) + }) }) }) diff --git a/webview-ui/src/utils/path-mentions.ts b/webview-ui/src/utils/path-mentions.ts index 960483f593..3021fe5069 100644 --- a/webview-ui/src/utils/path-mentions.ts +++ b/webview-ui/src/utils/path-mentions.ts @@ -12,11 +12,14 @@ * @returns A mention-friendly path */ export function convertToMentionPath(path: string, cwd?: string): string { - const normalizedPath = path.replace(/\\/g, "/") + // Strip file:// protocol if present + const pathWithoutProtocol = path.startsWith("file://") ? path.substring(7) : path + + const normalizedPath = pathWithoutProtocol.replace(/\\/g, "/") let normalizedCwd = cwd ? cwd.replace(/\\/g, "/") : "" if (!normalizedCwd) { - return path + return pathWithoutProtocol } // Remove trailing slash from cwd if it exists @@ -34,5 +37,5 @@ export function convertToMentionPath(path: string, cwd?: string): string { return "@" + (relativePath.startsWith("/") ? relativePath : "/" + relativePath) } - return path + return pathWithoutProtocol }