From 45381e566c1497d929c1237285c730cc8ff4847a Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 15 Nov 2023 11:05:09 +0100 Subject: [PATCH] Fix focus management on editor when renaming --- crates/editor2/src/editor.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 7edf8edc8c8e36e3c7f0e10f115561590dc02bda..e3d94409338269e663b4448509994b7f4ec8acc1 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -1880,10 +1880,8 @@ impl Editor { ); let focus_handle = cx.focus_handle(); - cx.on_focus_in(&focus_handle, Self::handle_focus_in) - .detach(); - cx.on_focus_out(&focus_handle, Self::handle_focus_out) - .detach(); + cx.on_focus(&focus_handle, Self::handle_focus).detach(); + cx.on_blur(&focus_handle, Self::handle_blur).detach(); let mut this = Self { handle: cx.view().downgrade(), @@ -7903,6 +7901,10 @@ impl Editor { cx: &mut ViewContext, ) -> Option { let rename = self.pending_rename.take()?; + if rename.editor.focus_handle(cx).is_focused(cx) { + cx.focus(&self.focus_handle); + } + self.remove_blocks( [rename.block_id].into_iter().collect(), Some(Autoscroll::fit()), @@ -9201,17 +9203,13 @@ impl Editor { self.focus_handle.is_focused(cx) } - fn handle_focus_in(&mut self, cx: &mut ViewContext) { - if self.focus_handle.is_focused(cx) { - // todo!() - // let focused_event = EditorFocused(cx.handle()); - // cx.emit_global(focused_event); - cx.emit(Event::Focused); - } + fn handle_focus(&mut self, cx: &mut ViewContext) { + cx.emit(Event::Focused); + if let Some(rename) = self.pending_rename.as_ref() { let rename_editor_focus_handle = rename.editor.read(cx).focus_handle.clone(); cx.focus(&rename_editor_focus_handle); - } else if self.focus_handle.is_focused(cx) { + } else { self.blink_manager.update(cx, BlinkManager::enable); self.buffer.update(cx, |buffer, cx| { buffer.finalize_last_transaction(cx); @@ -9227,7 +9225,7 @@ impl Editor { } } - fn handle_focus_out(&mut self, cx: &mut ViewContext) { + fn handle_blur(&mut self, cx: &mut ViewContext) { // todo!() // let blurred_event = EditorBlurred(cx.handle()); // cx.emit_global(blurred_event);