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

FR: Add an id parameter to documentOpen() #283

Open
olivroy opened this issue Aug 8, 2023 · 0 comments
Open

FR: Add an id parameter to documentOpen() #283

olivroy opened this issue Aug 8, 2023 · 0 comments

Comments

@olivroy
Copy link
Contributor

olivroy commented Aug 8, 2023

I am trying to write a wrapper that navigate to a file location of a potentially unsaved document. Therefore with

rstudioapi::getSourceEditorContext()$path
#> ""

However the file has a Rstudio id.

Therefore, I was wondering if documentOpen() could have an id parameter, so it would be possible to open an unsaved document to a specified location.

navigate_to_unsaved_file <- function(regex) {
 file_content <- rstudioapi::getSourceEditorContext()$content
 line_regex <- stringr::str_which(file_content, regex)
  rstudioapi::documentOpen(
    id = rstudioapi::getSourceEditorContext()$id,
    line = line_regex[1] # just using the first match for simplicity and example
  )
}

For reference, I am trying to achieve quarto-dev/quarto-cli#5335 with rstudioapi

Thanks

Edit: with an unsaved file,

rstudioapi::getSourceEditorContext()$id |> rstudioapi::documentPath()
Error in `Encoding<-`(`*tmp*`, value = "UTF-8") : 
  a character vector argument expected

Edit: using rstudioapi::setCursorPosition() works. However, it doesn't move focus to the required place (if my focus was on console, it remains this way) Maybe adding a moveCursor argument to setCursorPosition() would work?

@olivroy olivroy changed the title FR: Could documentOpen() have an id parameter FR: Add an id parameter to documentOpen() Aug 8, 2023
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

No branches or pull requests

1 participant