Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support language keyboard shortcuts in Quarto chunks #1955

Closed
Tracked by #4858
blairj09 opened this issue Dec 15, 2023 · 9 comments
Closed
Tracked by #4858

Support language keyboard shortcuts in Quarto chunks #1955

blairj09 opened this issue Dec 15, 2023 · 9 comments
Assignees
Labels
area: quarto Issues related to Quarto category.

Comments

@blairj09
Copy link

With an open R file, cmd+shift+m will automatically insert R pipe (|>). However, in an R code chunk within a Quarto document, the same shortcut instead opens the PROBLEMS panel. The VS Code keyboard shorcuts doc indicates that this is the expected behavior for this keybinding in VS Code:
image
However, it feels like Quarto chunks should prioritize language-specific key bindings. I intentionally left this issue title a bit vague in case there are other bindings that don't function as expected from within quarto chunks.

@juliasilge
Copy link
Contributor

Currently our rules for the pipe shortcut say editorLangId == r:

"command": "r.insertPipe",
"category": "R",
"title": "%r.command.insertPipe.title%",
"shortTitle": "%r.menu.insertPipe.title%",
"enablement": "editorLangId == r && editorTextFocus"

I don't know what Quarto currently gives us for editorLangId, given that it can be R, Python, etc.

Just to link these up, we are tracking some other related issues about Quarto and language features:

@jennybc
Copy link
Member

jennybc commented Dec 15, 2023

Some research ...

I just created a new Quarto document in positron and added an R chunk. With the cursor inside that chunk, I inspected context keys. editorLangId is 'quarto' and editorTextFocus is true.

https://code.visualstudio.com/api/references/when-clause-contexts#inspect-context-keys-utility

Screenshot 2023-12-15 at 1 46 06 PM

@petetronic petetronic added this to the Release Candidate milestone Feb 26, 2024
@wesm wesm added the area: quarto Issues related to Quarto category. label Feb 29, 2024
@juliasilge
Copy link
Contributor

This came up during usability testing with @gadenbuie today, and is a reason he shies away from using Quarto in Positron and/or VS Code.

@juliasilge
Copy link
Contributor

This came up in our private beta here: https://github.com/posit-dev/positron-beta/discussions/90

Should we do something easy and quick in the short term, like add the pipe shortcut to the RStudio keymap?

@juliasilge
Copy link
Contributor

After #3523 we have the shortcuts for |> and <- provided for Quarto files in the RStudio Keymap but in the long term we would like to support language keyboard shortcuts generally in Quarto chunks.

@kv9898
Copy link

kv9898 commented Aug 15, 2024

In the source mode it currently works like a charm! However, as noted in #4368, it still doesn't work in the visual mode

@melimelo24
Copy link

Quick hack around: modify the shortcuts directly (change when expression) to editorTextFocus && editorLangId == 'quarto' || editorTextFocus && editorLangId == 'r'. Works nicely for the pipe shortcut at least :)

@kv9898
Copy link

kv9898 commented Aug 30, 2024

Quick hack around: modify the shortcuts directly (change when expression) to editorTextFocus && editorLangId == 'quarto' || editorTextFocus && editorLangId == 'r'. Works nicely for the pipe shortcut at least :)

Thank you for your suggestion! I tried your proposed solution but sadly it didn't work for me (in the source mode it works as before, but in visual mode nothing happens)

@isabelizimm isabelizimm self-assigned this Nov 19, 2024
@juliasilge juliasilge self-assigned this Nov 22, 2024
juliasilge added a commit that referenced this issue Nov 27, 2024
Addresses #1955 together with
quarto-dev/quarto#608

The Quarto PR provides new context keys for the main language of a
Quarto document (for example, R or Python) and we can consume those to
provide keyboard shortcuts.

There are really only a couple of R ones that we want right now which
means that there is no real change here in an R `.qmd` in behavior
compared to what is in the RStudio Keymap. 🙈 However, I think this is
still worth getting in since we've gone to the trouble of figuring it
out, it lets us offer these without the RStudio Keymap being on, we can
offer them _only_ in R `.qmd` files (right now, these also show up in
Python `.qmd` files if you have the RStudio Keymap on), and we can use
this infrastructure in the future.

I did remove these from the RStudio Keymap just to clean things up, but
it wouldn't hurt _a lot_ to keep them, if there is some reason I am not
thinking of? If we do want to remove them, we'll need to do a Quarto
release and update the bundled Quarto VS Code extension version in this
PR to keep these keybindings functional.

### QA Notes

With the new version of the Quarto extension (updated here), you can use
the keyboard shortcuts for the pipe and assignment operator in R Quarto
documents but not Python ones:

- <kbd>Alt</kbd>+<kbd>-</kbd> to get you `<-`
- <kbd>Cmd/Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>M</kbd> to get you `|>`
@jonvanausdeln
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2024.12.0-96
Workbench Version(s):
OS Version(s) : Windows 11

Test scenario(s)

Keyboard shortcuts now work in Quarto document as expected.

Link(s) to TestRail test cases run or created:

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: quarto Issues related to Quarto category.
Projects
None yet
Development

No branches or pull requests

9 participants