windows: Fix opening wrong path when clicking path in the terminal view (#18726)

张小白 created

Closes #18550

This PR removes the prefix `\\?\`.

https://github.com/user-attachments/assets/f4f4333c-5d87-4f0f-b12c-fb2108703b6a


Release Notes:

- N/A

Change summary

crates/terminal_view/src/terminal_view.rs | 15 +++++++++++++++
1 file changed, 15 insertions(+)

Detailed changes

crates/terminal_view/src/terminal_view.rs 🔗

@@ -798,6 +798,7 @@ fn possible_open_paths_metadata(
     cx.background_executor().spawn(async move {
         let mut paths_with_metadata = Vec::with_capacity(potential_paths.len());
 
+        #[cfg(not(target_os = "windows"))]
         let mut fetch_metadata_tasks = potential_paths
             .into_iter()
             .map(|potential_path| async {
@@ -813,6 +814,20 @@ fn possible_open_paths_metadata(
             })
             .collect::<FuturesUnordered<_>>();
 
+        #[cfg(target_os = "windows")]
+        let mut fetch_metadata_tasks = potential_paths
+            .iter()
+            .map(|potential_path| async {
+                let metadata = fs.metadata(potential_path).await.ok().flatten();
+                let path = PathBuf::from(
+                    potential_path
+                        .to_string_lossy()
+                        .trim_start_matches("\\\\?\\"),
+                );
+                (PathWithPosition { path, row, column }, metadata)
+            })
+            .collect::<FuturesUnordered<_>>();
+
         while let Some((path, metadata)) = fetch_metadata_tasks.next().await {
             if let Some(metadata) = metadata {
                 paths_with_metadata.push((path, metadata));