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

This commit is contained in:
Matt Rubens 2025-04-16 23:04:16 -04:00 committed by GitHub
parent ba5af60109
commit 30c44ff14c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 4 deletions

View file

@ -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() !== "")

View file

@ -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",
)
})
})
})

View file

@ -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
}