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

Get editor context by document ID #251

Closed
gadenbuie opened this issue Feb 22, 2022 · 0 comments · Fixed by #253
Closed

Get editor context by document ID #251

gadenbuie opened this issue Feb 22, 2022 · 0 comments · Fixed by #253

Comments

@gadenbuie
Copy link
Member

Could rstudioapi include a method for obtaining the editor context by document ID? AFAICT, getSourceEditorContext() and getActiveDocumentContext() are the only way to get the current selection and contents for a document. In theory, one could use navigateToFile() to activate the required editor, read the source editor context, then switch back to the previously active editor... but there are a few problems:

  1. It's not possible to switch to an editor by context ID, meaning it may not be possible to switch back to the previously open editor (Allow switching to source editor by document ID #250)

  2. navigateToFile() is currently asynchronous, which introduces subtle timing issues that mean that one cannot simply call

    navigateToFile("code.R")
    getSourceEditorContext()

    since the second call will almost certainly return the editor context of the document that was active, not the context from the desired file code.R. (This will be fixed by API for document activation rstudio#8938)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant