Skip to content

Commit

Permalink
Move focus_handle method from WindowContext to AppContext
Browse files Browse the repository at this point in the history
  • Loading branch information
nathansobo committed Dec 17, 2024
1 parent 4d7cf44 commit 7f26c62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 13 additions & 5 deletions crates/gpui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -445,6 +446,7 @@ impl AppContext {
self.defer(move |_| activate());
subscription
}

pub(crate) fn observe_internal<W, E>(
&mut self,
entity: &E,
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions crates/gpui/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FocusHandle> {
self.window
Expand Down

0 comments on commit 7f26c62

Please sign in to comment.