R/altw.R

Defines functions altw

Documented in altw

#' Use clipr to copy selection(s) in current source editor to X clipboard
#'
#' @return NULL
#'
#' @author fnaufel
#' @export
#' @importFrom rstudioapi getSourceEditorContext insertText
#' @importFrom clipr write_clip
#'
altw <- function() {

  context <- rstudioapi::getSourceEditorContext()

  # Collect selection(s)
  my_text <- mapply(
    function(x) { paste0(x$text) },
    context$selection,
    USE.NAMES = FALSE
  )

  clipr::write_clip(my_text)

  # Deactivate selection by inserting selected text over itself (!)
  # This was the only way I found to do it :-(
  rstudioapi::insertText(my_text)

}
fnaufel/altw documentation built on April 16, 2022, 3:05 p.m.