From 6e363e464c9d0adc6153d76a1002fbebf3281215 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 16 Oct 2022 11:46:31 -0600 Subject: [PATCH] Start on view-level dispatch approach for keyboard events --- crates/chat_panel/src/chat_panel.rs | 2 +- crates/collab_ui/src/contact_finder.rs | 2 +- crates/collab_ui/src/contact_list.rs | 4 +- crates/collab_ui/src/contacts_popover.rs | 2 +- crates/command_palette/src/command_palette.rs | 2 +- crates/context_menu/src/context_menu.rs | 2 +- crates/diagnostics/src/diagnostics.rs | 2 +- crates/editor/src/editor.rs | 4 +- crates/file_finder/src/file_finder.rs | 2 +- crates/go_to_line/src/go_to_line.rs | 2 +- crates/gpui/src/app.rs | 188 +++++++++++++++--- crates/gpui/src/presenter.rs | 10 +- crates/outline/src/outline.rs | 2 +- crates/picker/src/picker.rs | 2 +- crates/project_symbols/src/project_symbols.rs | 2 +- crates/search/src/buffer_search.rs | 2 +- crates/search/src/project_search.rs | 2 +- .../terminal/src/terminal_container_view.rs | 2 +- crates/terminal/src/terminal_view.rs | 4 +- crates/theme_selector/src/theme_selector.rs | 2 +- crates/workspace/src/pane.rs | 2 +- crates/workspace/src/workspace.rs | 2 +- 22 files changed, 191 insertions(+), 53 deletions(-) diff --git a/crates/chat_panel/src/chat_panel.rs b/crates/chat_panel/src/chat_panel.rs index 0c22c21c7117ba59543d87dff65ebfe143b28a7c..ccd33db3abe4b8eb42f9ac5abf612cfa947303b0 100644 --- a/crates/chat_panel/src/chat_panel.rs +++ b/crates/chat_panel/src/chat_panel.rs @@ -397,7 +397,7 @@ impl View for ChatPanel { .boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if matches!( *self.rpc.status().borrow(), client::Status::Connected { .. } diff --git a/crates/collab_ui/src/contact_finder.rs b/crates/collab_ui/src/contact_finder.rs index a4ec02d2f00f20631206a3d0a2b868e4f226ae22..5165c3b1f690cc9eeeca491f4ebad7bb897be89e 100644 --- a/crates/collab_ui/src/contact_finder.rs +++ b/crates/collab_ui/src/contact_finder.rs @@ -36,7 +36,7 @@ impl View for ContactFinder { ChildView::new(self.picker.clone(), cx).boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.picker); } diff --git a/crates/collab_ui/src/contact_list.rs b/crates/collab_ui/src/contact_list.rs index cf8a8f8223e7ba5a0f06e548a59c4c34d3620ae8..7a51cc83ec5877e9b5485edfcbb5fc78515d6476 100644 --- a/crates/collab_ui/src/contact_list.rs +++ b/crates/collab_ui/src/contact_list.rs @@ -1121,13 +1121,13 @@ impl View for ContactList { .boxed() } - fn on_focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext) { if !self.filter_editor.is_focused(cx) { cx.focus(&self.filter_editor); } } - fn on_focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext) { + fn focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext) { if !self.filter_editor.is_focused(cx) { cx.emit(Event::Dismissed); } diff --git a/crates/collab_ui/src/contacts_popover.rs b/crates/collab_ui/src/contacts_popover.rs index 075255d72750bee57f8372b39570013b15d3a8a2..37280f929e7c9a5536588a4543d26f8fb8214282 100644 --- a/crates/collab_ui/src/contacts_popover.rs +++ b/crates/collab_ui/src/contacts_popover.rs @@ -160,7 +160,7 @@ impl View for ContactsPopover { .boxed() } - fn on_focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { match &self.child { Child::ContactList(child) => cx.focus(child), diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rs index 7702aaaf2a414e1c6791131aedafff11d27f099a..51474be1bed9ac13a57e5c05f54561d5a31a040d 100644 --- a/crates/command_palette/src/command_palette.rs +++ b/crates/command_palette/src/command_palette.rs @@ -135,7 +135,7 @@ impl View for CommandPalette { ChildView::new(self.picker.clone(), cx).boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.picker); } diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index c28437596669ea8453a8f714c62a81657015e71a..94031b4f6e8f30623b2a550629fb2d2dac910626 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -107,7 +107,7 @@ impl View for ContextMenu { .boxed() } - fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { self.reset(cx); } } diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 8180a6c9f61169502ac9a7114cee422da68d6329..4409fa17ad3669806ca1556a83a69d6a5e58fd87 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -99,7 +99,7 @@ impl View for ProjectDiagnosticsEditor { } } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if !self.path_states.is_empty() { cx.focus(&self.editor); } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 070fc69f7ebcfe1d974b2db2bccf5d45c19af200..670ec54933e6916bee31f1a9f8073ed17b7bf384 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6477,7 +6477,7 @@ impl View for Editor { "Editor" } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { let focused_event = EditorFocused(cx.handle()); cx.emit_global(focused_event); if let Some(rename) = self.pending_rename.as_ref() { @@ -6498,7 +6498,7 @@ impl View for Editor { } } - fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { let blurred_event = EditorBlurred(cx.handle()); cx.emit_global(blurred_event); self.focused = false; diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index e787e3c1a63c882398069c8efc81aa4515e826da..1a82613b84329eea6c214073185e26f886110fd2 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -53,7 +53,7 @@ impl View for FileFinder { ChildView::new(self.picker.clone(), cx).boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.picker); } diff --git a/crates/go_to_line/src/go_to_line.rs b/crates/go_to_line/src/go_to_line.rs index eddb014b63a4715e6268070ccc9f96897f0e50d5..ad1dacf7434e5bb30e7d4b04170aa0828e911b59 100644 --- a/crates/go_to_line/src/go_to_line.rs +++ b/crates/go_to_line/src/go_to_line.rs @@ -183,7 +183,7 @@ impl View for GoToLine { .named("go to line") } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { cx.focus(&self.line_editor); } } diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index a9529f3f9fccb67200aa944dd3509fda67432bc9..a9020cf35088a30488a8fb62ed1d0a547d37227b 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -41,8 +41,8 @@ use crate::{ platform::{self, KeyDownEvent, Platform, PromptLevel, WindowOptions}, presenter::Presenter, util::post_inc, - Appearance, AssetCache, AssetSource, ClipboardItem, FontCache, InputHandler, MouseButton, - MouseRegionId, PathPromptOptions, TextLayoutCache, + Appearance, AssetCache, AssetSource, ClipboardItem, FontCache, InputHandler, KeyUpEvent, + ModifiersChangedEvent, MouseButton, MouseRegionId, PathPromptOptions, TextLayoutCache, }; pub trait Entity: 'static { @@ -60,8 +60,18 @@ pub trait Entity: 'static { pub trait View: Entity + Sized { fn ui_name() -> &'static str; fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox; - fn on_focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext) {} - fn on_focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext) {} + fn focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext) {} + fn focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext) {} + fn key_down(&mut self, _: &KeyDownEvent, _: &mut ViewContext) -> bool { + false + } + fn key_up(&mut self, _: &KeyUpEvent, _: &mut ViewContext) -> bool { + false + } + fn modifiers_changed(&mut self, _: &ModifiersChangedEvent, _: &mut ViewContext) -> bool { + false + } + fn keymap_context(&self, _: &AppContext) -> keymap::Context { Self::default_keymap_context() } @@ -1297,7 +1307,7 @@ impl MutableAppContext { ) -> impl Iterator, SmallVec<[&Binding; 1]>)> { let mut action_types: HashSet<_> = self.global_actions.keys().copied().collect(); - for view_id in self.parents(window_id, view_id) { + for view_id in self.ancestors(window_id, view_id) { if let Some(view) = self.views.get(&(window_id, view_id)) { let view_type = view.as_any().type_id(); if let Some(actions) = self.actions.get(&view_type) { @@ -1327,7 +1337,7 @@ impl MutableAppContext { let action_type = action.as_any().type_id(); if let Some(window_id) = self.cx.platform.key_window_id() { if let Some(focused_view_id) = self.focused_view_id(window_id) { - for view_id in self.parents(window_id, focused_view_id) { + for view_id in self.ancestors(window_id, focused_view_id) { if let Some(view) = self.views.get(&(window_id, view_id)) { let view_type = view.as_any().type_id(); if let Some(actions) = self.actions.get(&view_type) { @@ -1376,7 +1386,7 @@ impl MutableAppContext { mut visit: impl FnMut(usize, bool, &mut MutableAppContext) -> bool, ) -> bool { // List of view ids from the leaf to the root of the window - let path = self.parents(window_id, view_id).collect::>(); + let path = self.ancestors(window_id, view_id).collect::>(); // Walk down from the root to the leaf calling visit with capture_phase = true for view_id in path.iter().rev() { @@ -1397,7 +1407,7 @@ impl MutableAppContext { // Returns an iterator over all of the view ids from the passed view up to the root of the window // Includes the passed view itself - fn parents(&self, window_id: usize, mut view_id: usize) -> impl Iterator + '_ { + fn ancestors(&self, window_id: usize, mut view_id: usize) -> impl Iterator + '_ { std::iter::once(view_id) .into_iter() .chain(std::iter::from_fn(move || { @@ -1445,11 +1455,81 @@ impl MutableAppContext { self.keystroke_matcher.clear_bindings(); } + pub fn dispatch_key_down(&mut self, window_id: usize, event: &KeyDownEvent) -> bool { + if let Some(focused_view_id) = self.focused_view_id(window_id) { + for view_id in self + .ancestors(window_id, focused_view_id) + .collect::>() + { + if let Some(mut view) = self.cx.views.remove(&(window_id, view_id)) { + let handled = view.key_down(event, self, window_id, view_id); + self.cx.views.insert((window_id, view_id), view); + if handled { + return true; + } + } else { + log::error!("view {} does not exist", view_id) + } + } + } + + false + } + + pub fn dispatch_key_up(&mut self, window_id: usize, event: &KeyUpEvent) -> bool { + if let Some(focused_view_id) = self.focused_view_id(window_id) { + for view_id in self + .ancestors(window_id, focused_view_id) + .collect::>() + { + if let Some(mut view) = self.cx.views.remove(&(window_id, view_id)) { + let handled = view.key_up(event, self, window_id, view_id); + self.cx.views.insert((window_id, view_id), view); + if handled { + return true; + } + } else { + log::error!("view {} does not exist", view_id) + } + } + } + + false + } + + pub fn dispatch_modifiers_changed( + &mut self, + window_id: usize, + event: &ModifiersChangedEvent, + ) -> bool { + if let Some(focused_view_id) = self.focused_view_id(window_id) { + for view_id in self + .ancestors(window_id, focused_view_id) + .collect::>() + { + if let Some(mut view) = self.cx.views.remove(&(window_id, view_id)) { + let handled = view.modifiers_changed(event, self, window_id, view_id); + self.cx.views.insert((window_id, view_id), view); + if handled { + return true; + } + } else { + log::error!("view {} does not exist", view_id) + } + } + } + + false + } + pub fn dispatch_keystroke(&mut self, window_id: usize, keystroke: &Keystroke) -> bool { let mut pending = false; if let Some(focused_view_id) = self.focused_view_id(window_id) { - for view_id in self.parents(window_id, focused_view_id).collect::>() { + for view_id in self + .ancestors(window_id, focused_view_id) + .collect::>() + { let keymap_context = self .cx .views @@ -1580,7 +1660,7 @@ impl MutableAppContext { is_fullscreen: false, }, ); - root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx)); + root_view.update(this, |view, cx| view.focus_in(cx.handle().into(), cx)); let window = this.cx @@ -1612,7 +1692,7 @@ impl MutableAppContext { is_fullscreen: false, }, ); - root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx)); + root_view.update(this, |view, cx| view.focus_in(cx.handle().into(), cx)); let status_item = this.cx.platform.add_status_item(); this.register_platform_window(window_id, status_item); @@ -2235,12 +2315,12 @@ impl MutableAppContext { //Handle focus let focused_id = window.focused_view_id?; - for view_id in this.parents(window_id, focused_id).collect::>() { + for view_id in this.ancestors(window_id, focused_id).collect::>() { if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) { if active { - view.on_focus_in(this, window_id, view_id, focused_id); + view.focus_in(this, window_id, view_id, focused_id); } else { - view.on_focus_out(this, window_id, view_id, focused_id); + view.focus_out(this, window_id, view_id, focused_id); } this.cx.views.insert((window_id, view_id), view); } @@ -2272,16 +2352,16 @@ impl MutableAppContext { }); let blurred_parents = blurred_id - .map(|blurred_id| this.parents(window_id, blurred_id).collect::>()) + .map(|blurred_id| this.ancestors(window_id, blurred_id).collect::>()) .unwrap_or_default(); let focused_parents = focused_id - .map(|focused_id| this.parents(window_id, focused_id).collect::>()) + .map(|focused_id| this.ancestors(window_id, focused_id).collect::>()) .unwrap_or_default(); if let Some(blurred_id) = blurred_id { for view_id in blurred_parents.iter().copied() { if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) { - view.on_focus_out(this, window_id, view_id, blurred_id); + view.focus_out(this, window_id, view_id, blurred_id); this.cx.views.insert((window_id, view_id), view); } } @@ -2294,7 +2374,7 @@ impl MutableAppContext { if let Some(focused_id) = focused_id { for view_id in focused_parents { if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) { - view.on_focus_in(this, window_id, view_id, focused_id); + view.focus_in(this, window_id, view_id, focused_id); this.cx.views.insert((window_id, view_id), view); } } @@ -2961,20 +3041,41 @@ pub trait AnyView { ) -> Option>>>; fn ui_name(&self) -> &'static str; fn render(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox; - fn on_focus_in( + fn focus_in( &mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize, focused_id: usize, ); - fn on_focus_out( + fn focus_out( &mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize, focused_id: usize, ); + fn key_down( + &mut self, + event: &KeyDownEvent, + cx: &mut MutableAppContext, + window_id: usize, + view_id: usize, + ) -> bool; + fn key_up( + &mut self, + event: &KeyUpEvent, + cx: &mut MutableAppContext, + window_id: usize, + view_id: usize, + ) -> bool; + fn modifiers_changed( + &mut self, + event: &ModifiersChangedEvent, + cx: &mut MutableAppContext, + window_id: usize, + view_id: usize, + ) -> bool; fn keymap_context(&self, cx: &AppContext) -> keymap::Context; fn debug_json(&self, cx: &AppContext) -> serde_json::Value; @@ -3040,7 +3141,7 @@ where View::render(self, &mut RenderContext::new(params, cx)) } - fn on_focus_in( + fn focus_in( &mut self, cx: &mut MutableAppContext, window_id: usize, @@ -3059,10 +3160,10 @@ where .type_id(); AnyViewHandle::new(window_id, focused_id, focused_type, cx.ref_counts.clone()) }; - View::on_focus_in(self, focused_view_handle, &mut cx); + View::focus_in(self, focused_view_handle, &mut cx); } - fn on_focus_out( + fn focus_out( &mut self, cx: &mut MutableAppContext, window_id: usize, @@ -3081,7 +3182,40 @@ where .type_id(); AnyViewHandle::new(window_id, blurred_id, blurred_type, cx.ref_counts.clone()) }; - View::on_focus_out(self, blurred_view_handle, &mut cx); + View::focus_out(self, blurred_view_handle, &mut cx); + } + + fn key_down( + &mut self, + event: &KeyDownEvent, + cx: &mut MutableAppContext, + window_id: usize, + view_id: usize, + ) -> bool { + let mut cx = ViewContext::new(cx, window_id, view_id); + View::key_down(self, event, &mut cx) + } + + fn key_up( + &mut self, + event: &KeyUpEvent, + cx: &mut MutableAppContext, + window_id: usize, + view_id: usize, + ) -> bool { + let mut cx = ViewContext::new(cx, window_id, view_id); + View::key_up(self, event, &mut cx) + } + + fn modifiers_changed( + &mut self, + event: &ModifiersChangedEvent, + cx: &mut MutableAppContext, + window_id: usize, + view_id: usize, + ) -> bool { + let mut cx = ViewContext::new(cx, window_id, view_id); + View::modifiers_changed(self, event, &mut cx) } fn keymap_context(&self, cx: &AppContext) -> keymap::Context { @@ -3463,7 +3597,7 @@ impl<'a, T: View> ViewContext<'a, T> { if self.window_id != view.window_id { return false; } - self.parents(view.window_id, view.view_id) + self.ancestors(view.window_id, view.view_id) .any(|parent| parent == self.view_id) } @@ -6354,13 +6488,13 @@ mod tests { "View" } - fn on_focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext) { if cx.handle().id() == focused.id() { self.events.lock().push(format!("{} focused", &self.name)); } } - fn on_focus_out(&mut self, blurred: AnyViewHandle, cx: &mut ViewContext) { + fn focus_out(&mut self, blurred: AnyViewHandle, cx: &mut ViewContext) { if cx.handle().id() == blurred.id() { self.events.lock().push(format!("{} blurred", &self.name)); } diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 9299a5c1fbff220e6f475dfcfc5e02eff9e43300..6e564414d33bce8b086c9d9dda3078f84199d348 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -232,10 +232,16 @@ impl Presenter { let mut mouse_events = SmallVec::<[_; 2]>::new(); let mut notified_views: HashSet = Default::default(); - // 1. Map the platform event into mouse events, which interact with mouse regions. + // 1. Handle platform event. Keyboard events get dispatched immediately, while mouse events + // get mapped into the mouse-specific MouseEvent type. // -> These are usually small: [Mouse Down] or [Mouse up, Click] or [Mouse Moved, Mouse Dragged?] // -> Also updates mouse-related state match &event { + Event::KeyDown(e) => return cx.dispatch_key_down(self.window_id, e), + Event::KeyUp(e) => return cx.dispatch_key_up(self.window_id, e), + Event::ModifiersChanged(e) => { + return cx.dispatch_modifiers_changed(self.window_id, e) + } Event::MouseDown(e) => { // Click events are weird because they can be fired after a drag event. // MDN says that browsers handle this by starting from 'the most @@ -345,8 +351,6 @@ impl Presenter { platform_event: e.clone(), })) } - - _ => {} } if let Some(position) = event.position() { diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rs index a677ab5b675a57bd4731bd760401ccfe1fafb248..cee5388800ab3a84c749dfc96cdbf371b551d61c 100644 --- a/crates/outline/src/outline.rs +++ b/crates/outline/src/outline.rs @@ -52,7 +52,7 @@ impl View for OutlineView { ChildView::new(self.picker.clone(), cx).boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.picker); } diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 30ad7827efce472959d3c833fc492bd1d45d8c3a..0945f6771bc6d640fb05a7df6233cbc6d71d71e7 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -116,7 +116,7 @@ impl View for Picker { cx } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.query_editor); } diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rs index a81231b98f38395c7ed67cef227fec407807b112..e4a251de00cdfc5de619c6e8d2beb305fadd1ea1 100644 --- a/crates/project_symbols/src/project_symbols.rs +++ b/crates/project_symbols/src/project_symbols.rs @@ -51,7 +51,7 @@ impl View for ProjectSymbolsView { ChildView::new(self.picker.clone(), cx).boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.picker); } diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index a43f3eb4867c7c9b1e27f1db278009cce26a6fcf..cd7a74ce8e3233f0d5b4404a3bc597ae4271b6a6 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -82,7 +82,7 @@ impl View for BufferSearchBar { "BufferSearchBar" } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.query_editor); } diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index eb5bf7d699480e9a240f93718f169f1979d0549f..8eb8e110e460972ada29f41f38150d5f8c08785f 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -195,7 +195,7 @@ impl View for ProjectSearchView { } } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { let handle = cx.weak_handle(); cx.update_global(|state: &mut ActiveSearches, cx| { state diff --git a/crates/terminal/src/terminal_container_view.rs b/crates/terminal/src/terminal_container_view.rs index 5cad16774d9f54ab2f173fb44678527bffaf55a5..d56631fd4f2fac5776a807f7bc657addd5347478 100644 --- a/crates/terminal/src/terminal_container_view.rs +++ b/crates/terminal/src/terminal_container_view.rs @@ -174,7 +174,7 @@ impl View for TerminalContainer { } } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(self.content.handle()); } diff --git a/crates/terminal/src/terminal_view.rs b/crates/terminal/src/terminal_view.rs index 732c0a717edddab1d42532252692aa57c814477c..0058198dc20932724d8e8428159d2df02643c459 100644 --- a/crates/terminal/src/terminal_view.rs +++ b/crates/terminal/src/terminal_view.rs @@ -343,14 +343,14 @@ impl View for TerminalView { .boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { self.has_new_content = false; self.terminal.read(cx).focus_in(); self.blink_cursors(self.blink_epoch, cx); cx.notify(); } - fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { self.terminal.update(cx, |terminal, _| { terminal.focus_out(); }); diff --git a/crates/theme_selector/src/theme_selector.rs b/crates/theme_selector/src/theme_selector.rs index 3236120857e229514eef37c251fa42aca8ec8b37..1caeae75f597050f145b8ebc36aa3a0b827261fc 100644 --- a/crates/theme_selector/src/theme_selector.rs +++ b/crates/theme_selector/src/theme_selector.rs @@ -266,7 +266,7 @@ impl View for ThemeSelector { ChildView::new(self.picker.clone(), cx).boxed() } - fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.picker); } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index b7ae7f2ba0b867dd7b57b9c9ed77fd2a9077ef29..882b501d2e59c3414589713d17c6752a9f69351c 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1485,7 +1485,7 @@ impl View for Pane { .named("pane") } - fn on_focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext) { if let Some(active_item) = self.active_item() { if cx.is_self_focused() { // Pane was focused directly. We need to either focus a view inside the active item, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index ece8cedfb1e516f8ff66fc8c76b3814c0fabd85b..82098a9d0649a45956008e964d080b660aa4cf74 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2656,7 +2656,7 @@ impl View for Workspace { .named("workspace") } - fn on_focus_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext) { + fn focus_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext) { if cx.is_self_focused() { cx.focus(&self.active_pane); } else {