From 85ff03cde047d4fd77931252ef4f31e141d3ce49 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 28 Oct 2024 17:21:41 -0700 Subject: [PATCH] Add more context to the save new file path picker (#19863) Release Notes: - N/A Co-authored-by: Conrad --- crates/file_finder/src/new_path_prompt.rs | 38 ++++++++++++++++++++-- crates/file_finder/src/open_path_prompt.rs | 6 +++- crates/picker/src/picker.rs | 8 +++-- crates/tasks_ui/src/modal.rs | 6 +++- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/crates/file_finder/src/new_path_prompt.rs b/crates/file_finder/src/new_path_prompt.rs index e992dd315f..d4492857b4 100644 --- a/crates/file_finder/src/new_path_prompt.rs +++ b/crates/file_finder/src/new_path_prompt.rs @@ -4,7 +4,7 @@ use gpui::{HighlightStyle, Model, StyledText}; use picker::{Picker, PickerDelegate}; use project::{Entry, PathMatchCandidateSet, Project, ProjectPath, WorktreeId}; use std::{ - path::PathBuf, + path::{Path, PathBuf}, sync::{ atomic::{self, AtomicBool}, Arc, @@ -254,6 +254,7 @@ impl PickerDelegate for NewPathDelegate { .trim() .trim_start_matches("./") .trim_start_matches('/'); + let (dir, suffix) = if let Some(index) = query.rfind('/') { let suffix = if index + 1 < query.len() { Some(query[index + 1..].to_string()) @@ -317,6 +318,14 @@ impl PickerDelegate for NewPathDelegate { }) } + fn confirm_completion( + &mut self, + _: String, + cx: &mut ViewContext>, + ) -> Option { + self.confirm_update_query(cx) + } + fn confirm_update_query(&mut self, cx: &mut ViewContext>) -> Option { let m = self.matches.get(self.selected_index)?; if m.is_dir(self.project.read(cx), cx) { @@ -422,7 +431,32 @@ impl NewPathDelegate { ) { cx.notify(); if query.is_empty() { - self.matches = vec![]; + self.matches = self + .project + .read(cx) + .worktrees(cx) + .flat_map(|worktree| { + let worktree_id = worktree.read(cx).id(); + worktree + .read(cx) + .child_entries(Path::new("")) + .filter_map(move |entry| { + entry.is_dir().then(|| Match { + path_match: Some(PathMatch { + score: 1.0, + positions: Default::default(), + worktree_id: worktree_id.to_usize(), + path: entry.path.clone(), + path_prefix: "".into(), + is_dir: entry.is_dir(), + distance_to_relative_ancestor: 0, + }), + suffix: None, + }) + }) + }) + .collect(); + return; } diff --git a/crates/file_finder/src/open_path_prompt.rs b/crates/file_finder/src/open_path_prompt.rs index 0736d4189b..be1e91b482 100644 --- a/crates/file_finder/src/open_path_prompt.rs +++ b/crates/file_finder/src/open_path_prompt.rs @@ -220,7 +220,11 @@ impl PickerDelegate for OpenPathDelegate { }) } - fn confirm_completion(&self, query: String) -> Option { + fn confirm_completion( + &mut self, + query: String, + _: &mut ViewContext>, + ) -> Option { Some( maybe!({ let m = self.matches.get(self.selected_index)?; diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index a9512606d2..5ebbcd3330 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -108,7 +108,11 @@ pub trait PickerDelegate: Sized + 'static { fn should_dismiss(&self) -> bool { true } - fn confirm_completion(&self, _query: String) -> Option { + fn confirm_completion( + &mut self, + _query: String, + _: &mut ViewContext>, + ) -> Option { None } @@ -370,7 +374,7 @@ impl Picker { } fn confirm_completion(&mut self, _: &ConfirmCompletion, cx: &mut ViewContext) { - if let Some(new_query) = self.delegate.confirm_completion(self.query(cx)) { + if let Some(new_query) = self.delegate.confirm_completion(self.query(cx), cx) { self.set_query(new_query, cx); } else { cx.propagate() diff --git a/crates/tasks_ui/src/modal.rs b/crates/tasks_ui/src/modal.rs index c18a0e6ba6..3de116702a 100644 --- a/crates/tasks_ui/src/modal.rs +++ b/crates/tasks_ui/src/modal.rs @@ -425,7 +425,11 @@ impl PickerDelegate for TasksModalDelegate { ) } - fn confirm_completion(&self, _: String) -> Option { + fn confirm_completion( + &mut self, + _: String, + _: &mut ViewContext>, + ) -> Option { let task_index = self.matches.get(self.selected_index())?.candidate_id; let tasks = self.candidates.as_ref()?; let (_, task) = tasks.get(task_index)?;