Select new files in the project panel after creating them

This commit is contained in:
Max Brunsfeld 2022-05-02 17:56:09 -07:00
parent a19766931d
commit 0ff39f1280
2 changed files with 15 additions and 8 deletions

View file

@ -379,7 +379,7 @@ impl FakeFs {
async fn simulate_random_delay(&self) { async fn simulate_random_delay(&self) {
self.executor self.executor
.upgrade() .upgrade()
.expect("excecutor has been dropped") .expect("executor has been dropped")
.simulate_random_delay() .simulate_random_delay()
.await; .await;
} }
@ -647,9 +647,16 @@ impl Fs for FakeFs {
let (tx, rx) = smol::channel::unbounded(); let (tx, rx) = smol::channel::unbounded();
state.event_txs.push(tx); state.event_txs.push(tx);
let path = path.to_path_buf(); let path = path.to_path_buf();
let executor = self.executor.clone();
Box::pin(futures::StreamExt::filter(rx, move |events| { Box::pin(futures::StreamExt::filter(rx, move |events| {
let result = events.iter().any(|event| event.path.starts_with(&path)); let result = events.iter().any(|event| event.path.starts_with(&path));
async move { result } let executor = executor.clone();
async move {
if let Some(executor) = executor.clone().upgrade() {
executor.simulate_random_delay().await;
}
result
}
})) }))
} }

View file

@ -295,9 +295,9 @@ impl ProjectPanel {
.save(new_path, Default::default(), cx) .save(new_path, Default::default(), cx)
}); });
Some(cx.spawn(|this, mut cx| async move { Some(cx.spawn(|this, mut cx| async move {
save.await?; let new_entry = save.await?;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.update_visible_entries(None, cx); this.update_visible_entries(Some((edit_state.worktree_id, new_entry.id)), cx);
cx.notify(); cx.notify();
}); });
Ok(()) Ok(())
@ -1005,12 +1005,12 @@ mod tests {
assert_eq!( assert_eq!(
visible_entries_as_strings(&panel, 0..10, cx), visible_entries_as_strings(&panel, 0..10, cx),
&[ &[
"v root1 <== selected", "v root1",
" > a", " > a",
" > b", " > b",
" > C", " > C",
" .dockerignore", " .dockerignore",
" the-new-filename", " the-new-filename <== selected",
"v root2", "v root2",
" > d", " > d",
" > e", " > e",
@ -1048,10 +1048,10 @@ mod tests {
&[ &[
"v root1", "v root1",
" > a", " > a",
" v b <== selected", " v b",
" > 3", " > 3",
" > 4", " > 4",
" another-filename", " another-filename <== selected",
" > C", " > C",
" .dockerignore", " .dockerignore",
" the-new-filename", " the-new-filename",