Switch from using the key window to the main window mac platform API

When the help menu is open, the help menu's search field is the key window, and this was causing menu item action resolution to fail

co-authored-by: Max <max@zed.dev>
This commit is contained in:
Mikayla Maki 2023-03-10 14:43:28 -08:00
parent 9398de6a57
commit adf94a1681
6 changed files with 12 additions and 12 deletions

View File

@ -1294,7 +1294,7 @@ impl MutableAppContext {
pub fn is_action_available(&self, action: &dyn Action) -> bool {
let action_type = action.as_any().type_id();
if let Some(window_id) = self.cx.platform.key_window_id() {
if let Some(window_id) = self.cx.platform.main_window_id() {
if let Some(focused_view_id) = self.focused_view_id(window_id) {
for view_id in self.ancestors(window_id, focused_view_id) {
if let Some(view) = self.views.get(&(window_id, view_id)) {

View File

@ -77,9 +77,9 @@ pub(crate) fn setup_menu_handlers(foreground_platform: &dyn ForegroundPlatform,
let cx = app.0.clone();
move |action| {
let mut cx = cx.borrow_mut();
if let Some(key_window_id) = cx.cx.platform.key_window_id() {
if let Some(view_id) = cx.focused_view_id(key_window_id) {
cx.handle_dispatch_action_from_effect(key_window_id, Some(view_id), action);
if let Some(main_window_id) = cx.cx.platform.main_window_id() {
if let Some(view_id) = cx.focused_view_id(main_window_id) {
cx.handle_dispatch_action_from_effect(main_window_id, Some(view_id), action);
return;
}
}

View File

@ -58,7 +58,7 @@ pub trait Platform: Send + Sync {
options: WindowOptions,
executor: Rc<executor::Foreground>,
) -> Box<dyn Window>;
fn key_window_id(&self) -> Option<usize>;
fn main_window_id(&self) -> Option<usize>;
fn add_status_item(&self) -> Box<dyn Window>;

View File

@ -587,8 +587,8 @@ impl platform::Platform for MacPlatform {
Box::new(Window::open(id, options, executor, self.fonts()))
}
fn key_window_id(&self) -> Option<usize> {
Window::key_window_id()
fn main_window_id(&self) -> Option<usize> {
Window::main_window_id()
}
fn add_status_item(&self) -> Box<dyn platform::Window> {

View File

@ -604,12 +604,12 @@ impl Window {
}
}
pub fn key_window_id() -> Option<usize> {
pub fn main_window_id() -> Option<usize> {
unsafe {
let app = NSApplication::sharedApplication(nil);
let key_window: id = msg_send![app, keyWindow];
if msg_send![key_window, isKindOfClass: WINDOW_CLASS] {
let id = get_window_state(&*key_window).borrow().id;
let main_window: id = msg_send![app, mainWindow];
if msg_send![main_window, isKindOfClass: WINDOW_CLASS] {
let id = get_window_state(&*main_window).borrow().id;
Some(id)
} else {
None

View File

@ -157,7 +157,7 @@ impl super::Platform for Platform {
}))
}
fn key_window_id(&self) -> Option<usize> {
fn main_window_id(&self) -> Option<usize> {
None
}