Title: | Get the current word or selection at cursor |
---|---|
Description: | Get the current word or selection at cursor using the {rstudioapi}. Works in VSCode and RStudio. |
Authors: | Miles McBain [aut, cre] |
Maintainer: | Miles McBain <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.2 |
Built: | 2024-10-27 02:47:26 UTC |
Source: | https://github.com/milesmcbain/atcursor |
get the column the cursor is on from a selection
get_cursor_col(current_selection)
get_cursor_col(current_selection)
current_selection |
a selection from the rstudioapi document context |
get the line the cursor is on
get_cursor_line( context, current_selection = rstudioapi::primary_selection(context) )
get_cursor_line( context, current_selection = rstudioapi::primary_selection(context) )
context |
the rtsudioapi document context |
current_selection |
the selection to find the line for, defaults to primary selection |
Uses the rstudioapi to get the word the cursor is on or active selection in the active document. This is useful for addins that want bind keys to trigger commands using the cursor context.
get_word_or_selection()
get_word_or_selection()
This function defines a word as a possibly namespaced R symbol. So a cursor
on the name of pkg::var(foo)
will return 'pkg::var'. $
is considered a separator.
If there are any selections the primary selection takes precedence and is returned.
a character vector containing the current word at the cursor or primary selection