From 98dce8937959a81a43b40555665c85da0ec3f920 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 14 Apr 2023 12:12:08 +0200 Subject: [PATCH] Pass `WindowContext` to `ViewHandle::is_focused` --- crates/copilot_button/src/copilot_button.rs | 2 +- crates/gpui/src/app.rs | 8 ++------ crates/project_panel/src/project_panel.rs | 7 +++++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/copilot_button/src/copilot_button.rs b/crates/copilot_button/src/copilot_button.rs index 072de103d1..a1fff79942 100644 --- a/crates/copilot_button/src/copilot_button.rs +++ b/crates/copilot_button/src/copilot_button.rs @@ -161,7 +161,7 @@ impl View for CopilotButton { )); let window_id = cx.window_id(); let task = task.to_owned(); - cx.spawn(|this, mut cx| async move { + cx.spawn_weak(|_this, mut cx| async move { task.await; cx.update(|cx| { if let Some(copilot) = Copilot::global(cx) { diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 96472f7951..697d9276e5 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -3928,12 +3928,8 @@ impl ViewHandle { }); } - #[cfg(any(test, feature = "test-support"))] - pub fn is_focused(&self, cx: &AppContext) -> bool { - cx.read_window(self.window_id, |cx| { - cx.focused_view_id() == Some(self.view_id) - }) - .unwrap_or(false) + pub fn is_focused(&self, cx: &WindowContext) -> bool { + cx.focused_view_id() == Some(self.view_id) } } diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 5e9ac30a1c..2ee884ea52 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -1549,7 +1549,7 @@ mod tests { .await; let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await; - let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); + let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); let panel = workspace.update(cx, |_, cx| ProjectPanel::new(project, cx)); select_path(&panel, "root1", cx); @@ -1571,7 +1571,10 @@ mod tests { // Add a file with the root folder selected. The filename editor is placed // before the first file in the root folder. panel.update(cx, |panel, cx| panel.new_file(&NewFile, cx)); - assert!(panel.read_with(cx, |panel, cx| panel.filename_editor.is_focused(cx))); + cx.read_window(window_id, |cx| { + let panel = panel.read(cx); + assert!(panel.filename_editor.is_focused(cx)); + }); assert_eq!( visible_entries_as_strings(&panel, 0..10, cx), &[