From bedf57db8941cfc893761ce7d44212b9d1175602 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 17 Jun 2024 11:31:49 +0200 Subject: [PATCH] Fix cursor blinking not working (#13130) This was a bug in https://github.com/zed-industries/zed/pull/12990, due to the new focus restoration logic introduced with the editor. With this pull request, the editor will only restore focus when a descendant lost it. If the focus was lost by the editor itself, there's no need to restore it and we can instead proceed with starting the cursor blink. Release Notes: - N/A --- crates/editor/src/editor.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 6ad0ca7fec07335adcb7163fe2424a27f63cb070..061f7b194c0eeb6aada3ba445a99e6060234dd9f 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -449,7 +449,7 @@ struct BufferOffset(usize); /// See the [module level documentation](self) for more information. pub struct Editor { focus_handle: FocusHandle, - last_focused: Option, + last_focused_descendant: Option, /// The text buffer being edited buffer: Model, /// Map of how text in the buffer should be displayed. @@ -1749,7 +1749,7 @@ impl Editor { let mut this = Self { focus_handle, - last_focused: None, + last_focused_descendant: None, buffer: buffer.clone(), display_map: display_map.clone(), selections, @@ -11321,12 +11321,12 @@ impl Editor { fn handle_focus(&mut self, cx: &mut ViewContext) { cx.emit(EditorEvent::Focused); - if let Some(last_focused) = self - .last_focused + if let Some(descendant) = self + .last_focused_descendant .take() - .and_then(|last_focused| last_focused.upgrade()) + .and_then(|descendant| descendant.upgrade()) { - cx.focus(&last_focused); + cx.focus(&descendant); } else { if let Some(blame) = self.blame.as_ref() { blame.update(cx, GitBlame::focus) @@ -11349,7 +11349,9 @@ impl Editor { } fn handle_focus_out(&mut self, event: FocusOutEvent, _cx: &mut ViewContext) { - self.last_focused = Some(event.blurred); + if event.blurred != self.focus_handle { + self.last_focused_descendant = Some(event.blurred); + } } pub fn handle_blur(&mut self, cx: &mut ViewContext) {