posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.78k stars 85 forks source link

Support Alt+Enter Keyboard Shortcut #2778

Open jaredlander opened 7 months ago

jaredlander commented 7 months ago

Positron Version:

Positron Version: 2024.03.0 (system setup) build 2024.03.0-6584 Code - OSS Version: 1.87.0 Commit: fe73a9a3a0e292970657bcb3fb9214eb9158e3e1 Date: 2024-04-01T03:18:17.396Z Electron: 27.3.2 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Windows_NT x64 10.0.22631

Steps to reproduce the issue:

  1. Put cursor on a line of code
  2. Press Alt+Enter

What did you expect to happen?

In RStudio this sends a line of code without the cursor moving to the next line (as Ctrl+Enter does). In Positron, nothing happened.

I'm sure I can edit the shortcuts myself, but since this is built in to RStudio I think users would expect it to be here as well.

Were there any error messages in the output or Developer Tools console?

None

juliasilge commented 7 months ago

As of today, we don't expose a way to control whether the cursor moves to the next line or not while executing code, so this isn't something that you can set up your own keybinding for right now. I will move this to our main repo as a feature request.

Thanks for the feedback! 🙌

juliasilge commented 7 months ago

In registerPositronConsoleActions() we create the action for executing code:

https://github.com/posit-dev/positron/blob/5ab781fa6a9e2b7bf733aecc8273807a8dbca634/src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts#L254

That action does a lot of work to move to the appropriate next line of code, but we could break that action up into two pieces, one of which is just executing the current statement and not computing newPosition. We can then bind that to Alt+Enter.

EKtheSage commented 4 months ago

Is there a way to standardize Alt + Enter for different language / file formats?

In quarto qmd files, if the language is python, pressing Alt + Enter in a cell chunk executes the current block of code, and "sometimes" move the cursor to the incorrect next block of code. Pressing Ctrl + Enter executes the whole cell and the cursor stays in the same position.

The image may be hard to tell, but the first image shows cursor on line 122, pressing Alt + Enter executes line 122 and 123, then jumps to line 129. I should expect the cursor to move to line 124 as the next statement to execute.

image

image

If the language is R, pressing Alt + Enter or Ctrl + Enter in a cell chunk executes the current block of code, and correctly moves the cursor to the next block of code.

In R scripts, pressing Ctrl + Enter in a cell chunk executes the current block of code, and correctly moves the cursor to the next block of code. Alt + Enter does nothing.

I really like Alt + Enter because it doesn't run all of the lines within a code cell, sometimes I need to run each block without breaking them up into individual cells.

juliasilge commented 4 months ago

If what you are looking for is a way to run a Python statement in a code chunk/cell but not the whole code chunk, then I think what you are looking for is this issue https://github.com/posit-dev/positron/issues/1646 and especially this comment https://github.com/posit-dev/positron/issues/1646#issuecomment-2135993785. Want to chime in there with anything additional?

Btibert3 commented 1 month ago

I recently asked this question and was directed to this chain so adding my +1 here as a feature request. The ability to jump ahead is fantastic, but there are situations where its favorable to run the current line and keep focus. My use case is for my class discussions where we write code together to learn.

Currently, I provide students with a templated script that we will use in class, and when its not a great experience to always skip to the end of the script and have to scroll back, especially for students learning to code.

The workaround at the moment is to select the snippets to run and use Command+ return (on a Mac). I will coach around it for now but it would be nice to have control on how code execution behaves.