From 28568429aa26260f273b86294b8f5d1bc5d95b7b Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 21 Aug 2024 09:38:12 +0200 Subject: [PATCH] collab panel: Unfocus filter editor on escape (#16579) This has been bugging me for a while, because it meant I was stuck in the collab panel when I accidentally navigated there via keyboard shortcuts. Now I can press esc and get out of that state. Release Notes: - Fixed `esc` not removing focus from the filter editor in the collaboration panel. ### Before https://github.com/user-attachments/assets/3bebac03-0e6a-49b0-9823-d9f3190aa5d2 ### After https://github.com/user-attachments/assets/d04c309d-9d1c-44b6-abd3-d48f55207e31 --- crates/collab_ui/src/collab_panel.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs index 0ff1131e679a19..dfef40efbcc27a 100644 --- a/crates/collab_ui/src/collab_panel.rs +++ b/crates/collab_ui/src/collab_panel.rs @@ -1395,15 +1395,22 @@ impl CollabPanel { cx.notify(); } + fn reset_filter_editor_text(&mut self, cx: &mut ViewContext) -> bool { + self.filter_editor.update(cx, |editor, cx| { + if editor.buffer().read(cx).len(cx) > 0 { + editor.set_text("", cx); + true + } else { + false + } + }) + } + fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext) { if self.take_editing_state(cx) { cx.focus_view(&self.filter_editor); - } else { - self.filter_editor.update(cx, |editor, cx| { - if editor.buffer().read(cx).len(cx) > 0 { - editor.set_text("", cx); - } - }); + } else if !self.reset_filter_editor_text(cx) { + self.focus_handle.focus(cx); } if self.context_menu.is_some() {