fix: Fix an issue which caused the focus to not be on `EncodingSelector` after an action was selected from `EncodingSaveOrReopenSelector`

R Aadarsh created

Change summary

crates/encodings/src/lib.rs       |  2 +-
crates/encodings/src/selectors.rs | 14 ++++++++------
2 files changed, 9 insertions(+), 7 deletions(-)

Detailed changes

crates/encodings/src/lib.rs 🔗

@@ -21,7 +21,7 @@ pub struct EncodingIndicator {
     pub encoding: Option<&'static dyn Encoding>,
     pub workspace: WeakEntity<Workspace>,
     observe: Option<Subscription>, // Subscription to observe changes in the active editor
-    show: bool,
+    show: bool, // Whether to show the indicator or not, based on whether an editor is active
 }
 
 pub mod selectors;

crates/encodings/src/selectors.rs 🔗

@@ -120,13 +120,14 @@ pub mod save_or_reopen {
 
                     workspace.update(cx, |workspace, cx| {
                         workspace.toggle_modal(window, cx, |window, cx| {
-                            EncodingSelector::new(
+                            let selector = EncodingSelector::new(
                                 window,
                                 cx,
                                 Action::Save,
                                 buffer.downgrade(),
                                 weak_workspace,
-                            )
+                            );
+                            selector
                         })
                     });
                 }
@@ -143,14 +144,15 @@ pub mod save_or_reopen {
 
                     workspace.update(cx, |workspace, cx| {
                         workspace.toggle_modal(window, cx, |window, cx| {
-                            EncodingSelector::new(
+                            let selector = EncodingSelector::new(
                                 window,
                                 cx,
                                 Action::Reopen,
                                 buffer.downgrade(),
                                 weak_workspace,
-                            )
-                        })
+                            );
+                            selector
+                        });
                     });
                 }
             }
@@ -516,7 +518,7 @@ pub mod encoding {
 
     impl Focusable for EncodingSelector {
         fn focus_handle(&self, cx: &ui::App) -> gpui::FocusHandle {
-            cx.focus_handle()
+            self.picker.focus_handle(cx)
         }
     }