From 1f974d074e6a77f21ff3b7315ed99357044b35ef Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Fri, 8 Nov 2024 17:11:43 -0800 Subject: [PATCH] Set up editor actions after workspace not on stack (#20445) Release Notes: - N/A Co-authored-by: Conrad Irwin --- crates/repl/src/repl_sessions_ui.rs | 61 +++++++++++++++-------------- crates/workspace/src/workspace.rs | 5 +++ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/crates/repl/src/repl_sessions_ui.rs b/crates/repl/src/repl_sessions_ui.rs index ae30d8cb9b..5b01b971ba 100644 --- a/crates/repl/src/repl_sessions_ui.rs +++ b/crates/repl/src/repl_sessions_ui.rs @@ -61,42 +61,45 @@ pub fn init(cx: &mut AppContext) { return; } - let is_local_project = editor - .workspace() - .map(|workspace| workspace.read(cx).project().read(cx).is_local()) - .unwrap_or(false); + cx.defer(|editor, cx| { + let workspace = Workspace::for_window(cx); - if !is_local_project { - return; - } + let is_local_project = workspace + .map(|workspace| workspace.read(cx).project().read(cx).is_local()) + .unwrap_or(false); - let editor_handle = cx.view().downgrade(); + if !is_local_project { + return; + } - editor - .register_action({ - let editor_handle = editor_handle.clone(); - move |_: &Run, cx| { - if !JupyterSettings::enabled(cx) { - return; + let editor_handle = cx.view().downgrade(); + + editor + .register_action({ + let editor_handle = editor_handle.clone(); + move |_: &Run, cx| { + if !JupyterSettings::enabled(cx) { + return; + } + + crate::run(editor_handle.clone(), true, cx).log_err(); } + }) + .detach(); - crate::run(editor_handle.clone(), true, cx).log_err(); - } - }) - .detach(); + editor + .register_action({ + let editor_handle = editor_handle.clone(); + move |_: &RunInPlace, cx| { + if !JupyterSettings::enabled(cx) { + return; + } - editor - .register_action({ - let editor_handle = editor_handle.clone(); - move |_: &RunInPlace, cx| { - if !JupyterSettings::enabled(cx) { - return; + crate::run(editor_handle.clone(), false, cx).log_err(); } - - crate::run(editor_handle.clone(), false, cx).log_err(); - } - }) - .detach(); + }) + .detach(); + }); }) .detach(); } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 43c8916593..02926e7572 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -4547,6 +4547,11 @@ impl Workspace { .children(leader_border), ) } + + pub fn for_window(cx: &mut WindowContext) -> Option> { + let window = cx.window_handle().downcast::()?; + cx.read_window(&window, |workspace, _| workspace).ok() + } } fn leader_border_for_pane(