Fix focus management on editor when renaming

This commit is contained in:
Antonio Scandurra 2023-11-15 11:05:09 +01:00
parent 003e4bc241
commit 45381e566c

View file

@ -1880,10 +1880,8 @@ impl Editor {
); );
let focus_handle = cx.focus_handle(); let focus_handle = cx.focus_handle();
cx.on_focus_in(&focus_handle, Self::handle_focus_in) cx.on_focus(&focus_handle, Self::handle_focus).detach();
.detach(); cx.on_blur(&focus_handle, Self::handle_blur).detach();
cx.on_focus_out(&focus_handle, Self::handle_focus_out)
.detach();
let mut this = Self { let mut this = Self {
handle: cx.view().downgrade(), handle: cx.view().downgrade(),
@ -7903,6 +7901,10 @@ impl Editor {
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Option<RenameState> { ) -> Option<RenameState> {
let rename = self.pending_rename.take()?; let rename = self.pending_rename.take()?;
if rename.editor.focus_handle(cx).is_focused(cx) {
cx.focus(&self.focus_handle);
}
self.remove_blocks( self.remove_blocks(
[rename.block_id].into_iter().collect(), [rename.block_id].into_iter().collect(),
Some(Autoscroll::fit()), Some(Autoscroll::fit()),
@ -9201,17 +9203,13 @@ impl Editor {
self.focus_handle.is_focused(cx) self.focus_handle.is_focused(cx)
} }
fn handle_focus_in(&mut self, cx: &mut ViewContext<Self>) { fn handle_focus(&mut self, cx: &mut ViewContext<Self>) {
if self.focus_handle.is_focused(cx) { cx.emit(Event::Focused);
// todo!()
// let focused_event = EditorFocused(cx.handle());
// cx.emit_global(focused_event);
cx.emit(Event::Focused);
}
if let Some(rename) = self.pending_rename.as_ref() { if let Some(rename) = self.pending_rename.as_ref() {
let rename_editor_focus_handle = rename.editor.read(cx).focus_handle.clone(); let rename_editor_focus_handle = rename.editor.read(cx).focus_handle.clone();
cx.focus(&rename_editor_focus_handle); cx.focus(&rename_editor_focus_handle);
} else if self.focus_handle.is_focused(cx) { } else {
self.blink_manager.update(cx, BlinkManager::enable); self.blink_manager.update(cx, BlinkManager::enable);
self.buffer.update(cx, |buffer, cx| { self.buffer.update(cx, |buffer, cx| {
buffer.finalize_last_transaction(cx); buffer.finalize_last_transaction(cx);
@ -9227,7 +9225,7 @@ impl Editor {
} }
} }
fn handle_focus_out(&mut self, cx: &mut ViewContext<Self>) { fn handle_blur(&mut self, cx: &mut ViewContext<Self>) {
// todo!() // todo!()
// let blurred_event = EditorBlurred(cx.handle()); // let blurred_event = EditorBlurred(cx.handle());
// cx.emit_global(blurred_event); // cx.emit_global(blurred_event);