소스 검색

Fix: Correct path handling for dragged files on Windows (#2753)

Felix NyxJae 8 달 전
부모
커밋
6772306ade
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      webview-ui/src/utils/path-mentions.ts

+ 12 - 1
webview-ui/src/utils/path-mentions.ts

@@ -13,7 +13,18 @@
  */
  */
 export function convertToMentionPath(path: string, cwd?: string): string {
 export function convertToMentionPath(path: string, cwd?: string): string {
 	// Strip file:// protocol if present
 	// 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, "/")
 	const normalizedPath = pathWithoutProtocol.replace(/\\/g, "/")
 	let normalizedCwd = cwd ? cwd.replace(/\\/g, "/") : ""
 	let normalizedCwd = cwd ? cwd.replace(/\\/g, "/") : ""