Skip to content

insertText() does not work in Positron #315

@davidkane9

Description

@davidkane9

I greatly appreciate the fact that some rstudioapi functions, like getSourceEditorContext() work in Positron. Thanks! But I do not think that insertText() works in Positron.

> rstudioapi::insertText(text = "hello")
Error:
! 'ranges' should be a list of 4-element integer vectors
Hide Traceback
    ▆
 1. └─rstudioapi::insertText(text = "hello")
 2.   └─rstudioapi::callFun(...)
 3.     ├─base::do.call(f, args)
 4.     └─`<fn>`(location = NULL, text = "hello", id = NULL)
 5.       └─asRangeList(location)
 6.         └─base::lapply(...)
 7.           └─FUN(X[[i]], ...)
>

Are there plans to have insertText() work in Positron? In the meantime, what approach do you recommend for achieving this when using Positron instead of RStudio?

UPDATE I: I am not sure if this is relevant, but here is what happens when I run the same command in R at the Terminal:

> rstudioapi::insertText(text = "hello")
Error: RStudio not running
> 

UPDATE II: ChatGPT suggested this approach:

rstudioapi::insertText(location = rstudioapi::getActiveDocumentContext()$selection[[1]]$range, text = "hello")

which does work. Feel free to close this issue if making the behavior of insertText() more similar across IDEs is not a priority.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions