positron icon indicating copy to clipboard operation
positron copied to clipboard

Support language keyboard shortcuts in Quarto chunks

Open blairj09 opened this issue 1 year ago • 6 comments

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.

blairj09 avatar Dec 15 '23 20:12 blairj09

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

https://github.com/posit-dev/positron/blob/de7666b74f2e3f2adfca059b6dc841ae3c6e9d86/extensions/positron-r/package.json#L32-L36

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:

  • #1572
  • #1805

juliasilge avatar Dec 15 '23 20:12 juliasilge

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

jennybc avatar Dec 15 '23 21:12 jennybc

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 avatar Mar 04 '24 22:03 juliasilge

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 avatar Apr 09 '24 10:04 juliasilge

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.

juliasilge avatar Jun 13 '24 01:06 juliasilge

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

kv9898 avatar Aug 15 '24 17:08 kv9898

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 :)

melimelo24 avatar Aug 30 '24 16:08 melimelo24

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)

kv9898 avatar Aug 30 '24 17:08 kv9898

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:

jonvanausdeln avatar Dec 02 '24 20:12 jonvanausdeln