Skip to content

Commit

Permalink
Set up editor actions after workspace not on stack (#20445)
Browse files Browse the repository at this point in the history
Release Notes:

- N/A

Co-authored-by: Conrad Irwin <[email protected]>
  • Loading branch information
rgbkrk and ConradIrwin authored Nov 9, 2024
1 parent 7212594 commit 1f974d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
65 changes: 34 additions & 31 deletions crates/repl/src/repl_sessions_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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 |_: &Run, cx| {
if !JupyterSettings::enabled(cx) {
return;
}

crate::run(editor_handle.clone(), false, 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;
}

crate::run(editor_handle.clone(), false, cx).log_err();
}
})
.detach();
});
})
.detach();
}
Expand Down
5 changes: 5 additions & 0 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4547,6 +4547,11 @@ impl Workspace {
.children(leader_border),
)
}

pub fn for_window(cx: &mut WindowContext) -> Option<View<Workspace>> {
let window = cx.window_handle().downcast::<Workspace>()?;
cx.read_window(&window, |workspace, _| workspace).ok()
}
}

fn leader_border_for_pane(
Expand Down

0 comments on commit 1f974d0

Please sign in to comment.