Skip to content

Commit 30c44ff

Browse files
authored
Support dragging and dropping tabs into chat text area (#2698)
1 parent ba5af60 commit 30c44ff

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
612612
e.preventDefault()
613613
setIsDraggingOver(false)
614614

615-
const text = e.dataTransfer.getData("text")
615+
const text = e.dataTransfer.getData("application/vnd.code.uri-list")
616616
if (text) {
617617
// Split text on newlines to handle multiple files
618618
const lines = text.split(/\r?\n/).filter((line) => line.trim() !== "")

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,20 @@ describe("path-mentions", () => {
4141
"@/nested/deeply/file.txt",
4242
)
4343
})
44+
45+
it("should strip file:// protocol from paths if present", () => {
46+
// Without cwd
47+
expect(convertToMentionPath("file:///Users/user/project/file.txt")).toBe("/Users/user/project/file.txt")
48+
49+
// With cwd - should strip protocol and then apply mention path logic
50+
expect(convertToMentionPath("file:///Users/user/project/file.txt", "/Users/user/project")).toBe(
51+
"@/file.txt",
52+
)
53+
54+
// With Windows paths
55+
expect(convertToMentionPath("file://C:/Users/user/project/file.txt", "C:/Users/user/project")).toBe(
56+
"@/file.txt",
57+
)
58+
})
4459
})
4560
})

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
* @returns A mention-friendly path
1313
*/
1414
export function convertToMentionPath(path: string, cwd?: string): string {
15-
const normalizedPath = path.replace(/\\/g, "/")
15+
// Strip file:// protocol if present
16+
const pathWithoutProtocol = path.startsWith("file://") ? path.substring(7) : path
17+
18+
const normalizedPath = pathWithoutProtocol.replace(/\\/g, "/")
1619
let normalizedCwd = cwd ? cwd.replace(/\\/g, "/") : ""
1720

1821
if (!normalizedCwd) {
19-
return path
22+
return pathWithoutProtocol
2023
}
2124

2225
// Remove trailing slash from cwd if it exists
@@ -34,5 +37,5 @@ export function convertToMentionPath(path: string, cwd?: string): string {
3437
return "@" + (relativePath.startsWith("/") ? relativePath : "/" + relativePath)
3538
}
3639

37-
return path
40+
return pathWithoutProtocol
3841
}

0 commit comments

Comments
 (0)