Getting the cursor position in Addin Function


#1

Hello,
I’m trying to write an addin that will, given the location of a cursor, select the chunk code (i’m working with Rmarkdown).
That is

1:{r} 2:... 3. ... n:

If the user has their cursor somewhere between lines 1 and n, i will grab the selection corresponding to lines 2 … (n-1).

a) is there a keyboard shortcut corresponding to this? (note, R wont be the only engine, I’m using a custom engine)
b) if not, is there an rstudioAPI function to get the current cursor position in the document?


#2

To answer (b), use primary_selection. it will return the cursr location.

$range
Document Range:
- Start: [19, 13]
- End: [19, 13]

$text
[1] ""