From c1dfb6294b152f9ebfa958dd0cac945c41111ee2 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 18 Jul 2022 16:10:09 -0700 Subject: [PATCH] Dismiss project panel's rename editor when it loses focus --- crates/project_panel/src/project_panel.rs | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index eaff23a476..a2034dc679 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -184,6 +184,20 @@ impl ProjectPanel { ) }); + cx.observe_focus(&filename_editor, |this, _, is_focused, cx| { + if !is_focused { + if this + .edit_state + .as_ref() + .map_or(false, |state| state.processing_filename.is_none()) + { + this.edit_state = None; + this.update_visible_entries(None, cx); + } + } + }) + .detach(); + let mut this = Self { project: project.clone(), list: Default::default(), @@ -1544,6 +1558,41 @@ mod tests { " .dockerignore", ] ); + + panel.update(cx, |panel, cx| panel.rename(&Default::default(), cx)); + assert_eq!( + visible_entries_as_strings(&panel, 0..10, cx), + &[ + "v root1", + " > .git", + " > a", + " v b", + " > [EDITOR: '3'] <== selected", + " > 4", + " > new-dir", + " a-different-filename", + " > C", + " .dockerignore", + ] + ); + + // Dismiss the rename editor when it loses focus. + workspace.update(cx, |_, cx| cx.focus_self()); + assert_eq!( + visible_entries_as_strings(&panel, 0..10, cx), + &[ + "v root1", + " > .git", + " > a", + " v b", + " > 3 <== selected", + " > 4", + " > new-dir", + " a-different-filename", + " > C", + " .dockerignore", + ] + ); } fn toggle_expand_dir(