rstudio / rstudioapi

Safely access RStudio's API (when available)
http://rstudio.github.io/rstudioapi
Other
165 stars 35 forks source link

Allow switching to source editor by document ID #250

Open gadenbuie opened 2 years ago

gadenbuie commented 2 years ago

AFAICT it's currently not possible to activate a source editor by document ID, which makes unsaved documents inaccessible to automation when they lose focus.

library(rstudioapi)

documentNew("# first document")
id1 <- getSourceEditorContext()

# we have context for first document, open a second doc
documentNew("# second document")
id2 <- getSourceEditorContext()

# cannot re-activate first document
gadenbuie commented 2 years ago

I just followed a few internal Slack conversation threads and realized that https://github.com/rstudio/rstudio/issues/8938 is intended to support a feature like this where the proposal was for

something like documentActivate(), that accepts either a document ID or a document path.