diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json index f8178efe11c140..cd5b40f68a4a9e 100644 --- a/assets/keymaps/default-linux.json +++ b/assets/keymaps/default-linux.json @@ -479,7 +479,8 @@ { "context": "Editor && jupyter && !ContextEditor", "bindings": { - "ctrl-shift-enter": "repl::Run" + "ctrl-shift-enter": "repl::Run", + "ctrl-alt-enter": "repl::RunInPlace" } }, { diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json index e84d596d27acb4..fccf287a55b61e 100644 --- a/assets/keymaps/default-macos.json +++ b/assets/keymaps/default-macos.json @@ -178,7 +178,8 @@ { "context": "Editor && jupyter && !ContextEditor", "bindings": { - "ctrl-shift-enter": "repl::Run" + "ctrl-shift-enter": "repl::Run", + "ctrl-alt-enter": "repl::RunInPlace" } }, { diff --git a/crates/quick_action_bar/src/repl_menu.rs b/crates/quick_action_bar/src/repl_menu.rs index 0ee47a9ba06dc6..3f0bc1411406a0 100644 --- a/crates/quick_action_bar/src/repl_menu.rs +++ b/crates/quick_action_bar/src/repl_menu.rs @@ -134,7 +134,7 @@ impl QuickActionBar { { let editor = editor.clone(); move |cx| { - repl::run(editor.clone(), cx).log_err(); + repl::run(editor.clone(), true, cx).log_err(); } }, ) diff --git a/crates/repl/src/repl_editor.rs b/crates/repl/src/repl_editor.rs index 1af7fd99d63d1c..fe0252431db09a 100644 --- a/crates/repl/src/repl_editor.rs +++ b/crates/repl/src/repl_editor.rs @@ -12,7 +12,7 @@ use crate::repl_store::ReplStore; use crate::session::SessionEvent; use crate::{KernelSpecification, Session}; -pub fn run(editor: WeakView, cx: &mut WindowContext) -> Result<()> { +pub fn run(editor: WeakView, move_down: bool, cx: &mut WindowContext) -> Result<()> { let store = ReplStore::global(cx); if !store.read(cx).is_enabled() { return Ok(()); @@ -89,7 +89,7 @@ pub fn run(editor: WeakView, cx: &mut WindowContext) -> Result<()> { } session.update(cx, |session, cx| { - session.execute(selected_text, anchor_range, next_cursor, cx); + session.execute(selected_text, anchor_range, next_cursor, move_down, cx); }); } diff --git a/crates/repl/src/repl_sessions_ui.rs b/crates/repl/src/repl_sessions_ui.rs index bd097e99be8a23..f646cde21cfcdb 100644 --- a/crates/repl/src/repl_sessions_ui.rs +++ b/crates/repl/src/repl_sessions_ui.rs @@ -17,6 +17,7 @@ actions!( repl, [ Run, + RunInPlace, ClearOutputs, Sessions, Interrupt, @@ -68,7 +69,20 @@ pub fn init(cx: &mut AppContext) { return; } - crate::run(editor_handle.clone(), cx).log_err(); + 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(); diff --git a/crates/repl/src/session.rs b/crates/repl/src/session.rs index a7922428cefe90..5ca54c0eba3b93 100644 --- a/crates/repl/src/session.rs +++ b/crates/repl/src/session.rs @@ -417,6 +417,7 @@ impl Session { code: String, anchor_range: Range, next_cell: Option, + move_down: bool, cx: &mut ViewContext, ) { let Some(editor) = self.editor.upgrade() else { @@ -519,12 +520,13 @@ impl Session { _ => {} } - // Now move the cursor to after the block - editor.update(cx, move |editor, cx| { - editor.change_selections(Some(Autoscroll::top_relative(8)), cx, |selections| { - selections.select_ranges([new_cursor_pos..new_cursor_pos]); + if move_down { + editor.update(cx, move |editor, cx| { + editor.change_selections(Some(Autoscroll::top_relative(8)), cx, |selections| { + selections.select_ranges([new_cursor_pos..new_cursor_pos]); + }); }); - }); + } } fn route(&mut self, message: &JupyterMessage, cx: &mut ViewContext) {