From 7f26c628f17be57bea4cf7e3d237647fe4030b09 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 17 Dec 2024 13:04:55 -0700 Subject: [PATCH] Move focus_handle method from WindowContext to AppContext --- crates/gpui/src/app.rs | 18 +++++++++++++----- crates/gpui/src/window.rs | 6 ------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 426dcade384be..33cabc000f47a 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -34,11 +34,12 @@ use util::ResultExt; use crate::{ current_platform, hash, init_app_menus, Action, ActionRegistry, Any, AnyView, AnyWindowHandle, Asset, AssetSource, BackgroundExecutor, ClipboardItem, Context, DispatchPhase, DisplayId, - Entity, EventEmitter, FocusId, ForegroundExecutor, Global, KeyBinding, Keymap, Keystroke, - LayoutId, Menu, MenuItem, OwnedMenu, PathPromptOptions, Pixels, Platform, PlatformDisplay, - Point, PromptBuilder, PromptHandle, PromptLevel, Render, RenderablePromptHandle, Reservation, - ScreenCaptureSource, SharedString, SubscriberSet, Subscription, SvgRenderer, Task, TextSystem, - View, ViewContext, Window, WindowAppearance, WindowContext, WindowHandle, WindowId, + Entity, EventEmitter, FocusHandle, FocusId, ForegroundExecutor, Global, KeyBinding, Keymap, + Keystroke, LayoutId, Menu, MenuItem, OwnedMenu, PathPromptOptions, Pixels, Platform, + PlatformDisplay, Point, PromptBuilder, PromptHandle, PromptLevel, Render, + RenderablePromptHandle, Reservation, ScreenCaptureSource, SharedString, SubscriberSet, + Subscription, SvgRenderer, Task, TextSystem, View, ViewContext, Window, WindowAppearance, + WindowContext, WindowHandle, WindowId, }; mod async_context; @@ -445,6 +446,7 @@ impl AppContext { self.defer(move |_| activate()); subscription } + pub(crate) fn observe_internal( &mut self, entity: &E, @@ -575,6 +577,12 @@ impl AppContext { }) } + /// Obtain a new [`FocusHandle`], which allows you to track and manipulate the keyboard focus + /// for elements rendered within this window. + pub fn focus_handle(&self) -> FocusHandle { + FocusHandle::new(&self.focus_handles) + } + /// Instructs the platform to activate the application by bringing it to the foreground. pub fn activate(&self, ignoring_other_apps: bool) { self.platform.activate(ignoring_other_apps); diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index f100e27a5c29a..bbb1e99fa262c 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -929,12 +929,6 @@ impl<'a> WindowContext<'a> { self.window.removed = true; } - /// Obtain a new [`FocusHandle`], which allows you to track and manipulate the keyboard focus - /// for elements rendered within this window. - pub fn focus_handle(&self) -> FocusHandle { - FocusHandle::new(&self.app.focus_handles) - } - /// Obtain the currently focused [`FocusHandle`]. If no elements are focused, returns `None`. pub fn focused(&self) -> Option { self.window