rstudio / rstudioapi

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

Retrieving information about source document should include the mod (Source vs Visual) when applicable #266

Open daattali opened 1 year ago

daattali commented 1 year ago

Related to #265

When trying to work with Rmd/Qmd files, it may be helpful to know whether the script is currently open in Source or in Visual mode.

I do see that there are a few functions that are meant to work with visual mode eg. documentId(), selectionGet() - but these only work for the currently active document, so if I run them from the commandline they don't return something useful.

GegznaV commented 12 months ago

Is there any progress towards solving this issue?

kevinushey commented 12 months ago

Any thoughts on the right fix? Should we add something like documentEditorMode() for querying the editor mode type, or include that as part of the other "context" requests?

GegznaV commented 12 months ago

I think, the output of rstudioapi::getActiveDocumentContext() and friends could have an additional field, e.g., editor_mode with values visual or source or is_visual_mode with values TRUE or FALSE.

GegznaV commented 12 months ago

@kevinushey, is there a way to know which type of Visual Editor's content a cursor is in? E.g., is it in the R code block, in heading 1 or heading 3 block, or a regular text block? I.e., in theory, can this type of information be also retrieved?