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

Left assignment operator shortcut overrides macOS keyboard shortcut outside of R contexts in Quarto files #6684

Open
andrewheiss opened this issue Mar 7, 2025 · 1 comment
Labels
area: quarto Issues related to Quarto category. enhancement New feature or request support

Comments

@andrewheiss
Copy link

System details:

Positron and OS details:

Positron Version: 2025.03.0 (Universal) build 116
Code - OSS Version: 1.96.0
Commit: 7f0f938
Date: 2025-03-01T18:51:44.014Z
Electron: 32.2.6
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.3.0

Interpreter details:

R 4.4.2 + Quarto 1.7.13

Describe the issue:

(I'm not sure if this is a Quarto extension issue or a Positron issue—it's weird behavior nonetheless.)

On macOS, the keystroke ⌥- (alt/option + -) inserts an en-dash (–). In Positron (inheriting from RStudio settings), ⌥- inserts the left assignment operator <-. That's all great and fine—there's rarely any reason to use proper en-dashes in R code (beyond things like typographically correct plot titles).

Positron includes a keybinding setting in the R language pack called 'R: Insert the "<-" assignment operator', which contains this:

{
  "key": "alt+-",
  "command": "r.insertLeftAssignment",
  "when": "editorTextFocus && editorLangId == 'r' || editorTextFocus && quarto.document.languageId == 'r'"
}

It makes Positron insert a <- in R scripts and Quarto documents that use R.

However, it seems to be a little too aggressive in when it is enabled. Here are some little videos to illustrate what's happening…

Steps to reproduce the issue:

On macOS, in a new Quarto document with no code chunks, alt+- inserts an en-dash as expected:

part-1.mov

If a Python chunk is added, alt+- continues to insert an en-dash, both in the code chunk and in the Markdown area. This is good and expected—<- isn't a thing in Python:

part-2.mov

If an R chunk is added, alt+- inserts a <- in the R chunk, which is good and expected, BUT it also inserts a <- outside of the chunk in the Markdown. This is unexpected.

part-3.mov

If the R chunk is removed, alt+- returns to working with en-dashes:

part-4.mov

Essentially, if there's an R chunk anywhere in a Quarto document, alt+- inserts <- in all contexts (YAML, Markdown, R). If the document contains chunks with multiple languages (e.g., R and Python), alt+- will insert <- in the other language chunks too. The existence of an R chunk enables the left assignment shortcut for the whole document.

Expected or desired behavior

It would be nice if the alt+- shortcut could be limited to only R code chunks. My current workaround is to use a systemwide keyboard shortcut (;enn) that expands to an en-dash—I just have to remember to use it when working in Markdown in Positron 🤷‍♂️

@juliasilge
Copy link
Contributor

To get this working better, we need to implement a context key that is like quarto.cell.languageId, similar to how we implemented quarto.document.languageId in quarto-dev/quarto#608. That was my original goal in that PR, but everything I tried there for a per-cell context key did NOT work well; we'd need to revisit and see if we can find a better approach.

@juliasilge juliasilge added area: quarto Issues related to Quarto category. enhancement New feature or request support labels Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: quarto Issues related to Quarto category. enhancement New feature or request support
Projects
None yet
Development

No branches or pull requests

2 participants