repl: Add ctrl-alt-enter binding to run in place (#15743)
Release Notes: - Added `ctrl-alt-enter` keybinding for `repl::RunInPlace` (`ctrl-option-enter` on MacOS). Keeps your screen position and cursor in place when running any block.
This commit is contained in:
parent
b7eae7fbd9
commit
f8234aec6a
6 changed files with 29 additions and 11 deletions
|
@ -479,7 +479,8 @@
|
||||||
{
|
{
|
||||||
"context": "Editor && jupyter && !ContextEditor",
|
"context": "Editor && jupyter && !ContextEditor",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"ctrl-shift-enter": "repl::Run"
|
"ctrl-shift-enter": "repl::Run",
|
||||||
|
"ctrl-alt-enter": "repl::RunInPlace"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -178,7 +178,8 @@
|
||||||
{
|
{
|
||||||
"context": "Editor && jupyter && !ContextEditor",
|
"context": "Editor && jupyter && !ContextEditor",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"ctrl-shift-enter": "repl::Run"
|
"ctrl-shift-enter": "repl::Run",
|
||||||
|
"ctrl-alt-enter": "repl::RunInPlace"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -134,7 +134,7 @@ impl QuickActionBar {
|
||||||
{
|
{
|
||||||
let editor = editor.clone();
|
let editor = editor.clone();
|
||||||
move |cx| {
|
move |cx| {
|
||||||
repl::run(editor.clone(), cx).log_err();
|
repl::run(editor.clone(), true, cx).log_err();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::repl_store::ReplStore;
|
||||||
use crate::session::SessionEvent;
|
use crate::session::SessionEvent;
|
||||||
use crate::{KernelSpecification, Session};
|
use crate::{KernelSpecification, Session};
|
||||||
|
|
||||||
pub fn run(editor: WeakView<Editor>, cx: &mut WindowContext) -> Result<()> {
|
pub fn run(editor: WeakView<Editor>, move_down: bool, cx: &mut WindowContext) -> Result<()> {
|
||||||
let store = ReplStore::global(cx);
|
let store = ReplStore::global(cx);
|
||||||
if !store.read(cx).is_enabled() {
|
if !store.read(cx).is_enabled() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -89,7 +89,7 @@ pub fn run(editor: WeakView<Editor>, cx: &mut WindowContext) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
session.update(cx, |session, cx| {
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ actions!(
|
||||||
repl,
|
repl,
|
||||||
[
|
[
|
||||||
Run,
|
Run,
|
||||||
|
RunInPlace,
|
||||||
ClearOutputs,
|
ClearOutputs,
|
||||||
Sessions,
|
Sessions,
|
||||||
Interrupt,
|
Interrupt,
|
||||||
|
@ -68,7 +69,20 @@ pub fn init(cx: &mut AppContext) {
|
||||||
return;
|
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();
|
.detach();
|
||||||
|
|
|
@ -417,6 +417,7 @@ impl Session {
|
||||||
code: String,
|
code: String,
|
||||||
anchor_range: Range<Anchor>,
|
anchor_range: Range<Anchor>,
|
||||||
next_cell: Option<Anchor>,
|
next_cell: Option<Anchor>,
|
||||||
|
move_down: bool,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let Some(editor) = self.editor.upgrade() else {
|
let Some(editor) = self.editor.upgrade() else {
|
||||||
|
@ -519,13 +520,14 @@ impl Session {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now move the cursor to after the block
|
if move_down {
|
||||||
editor.update(cx, move |editor, cx| {
|
editor.update(cx, move |editor, cx| {
|
||||||
editor.change_selections(Some(Autoscroll::top_relative(8)), cx, |selections| {
|
editor.change_selections(Some(Autoscroll::top_relative(8)), cx, |selections| {
|
||||||
selections.select_ranges([new_cursor_pos..new_cursor_pos]);
|
selections.select_ranges([new_cursor_pos..new_cursor_pos]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn route(&mut self, message: &JupyterMessage, cx: &mut ViewContext<Self>) {
|
fn route(&mut self, message: &JupyterMessage, cx: &mut ViewContext<Self>) {
|
||||||
let parent_message_id = match message.parent_header.as_ref() {
|
let parent_message_id = match message.parent_header.as_ref() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue