Browse Source

Support dragging and dropping tabs into chat text area (#2698)

Matt Rubens 9 months ago
parent
commit
30c44ff14c

+ 1 - 1
webview-ui/src/components/chat/ChatTextArea.tsx

@@ -612,7 +612,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
 				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() !== "")

+ 15 - 0
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",
+			)
+		})
 	})
 })

+ 6 - 3
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
 }