-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from saurfang/autocomplete-list
[WIP][Completion] Configurable Completers
- Loading branch information
Showing
6 changed files
with
110 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
#' Enable Code Completion for an Ace Code Input | ||
#' | ||
#' | ||
#' This function dynamically auto complete R code pieces using built-in function | ||
#' \code{utils:::.win32consoleCompletion}. Please see \code{\link[utils]{rcompgen}} for details. | ||
#' | ||
#' | ||
#' @details | ||
#' You can implement your own code completer by listening to \code{input$shinyAce_<editorId>_hint} | ||
#' where <editorId> is the \code{aceEditor} id. The input contains | ||
#' \itemize{ | ||
#' \item \code{linebuffer}: Code/Text at current editing line | ||
#' \item \code{cursorPosition}: Current cursor position at this line | ||
#' } | ||
#' | ||
#' | ||
#' @param inputId The id of the input object | ||
#' @param session The \code{session} object passed to function given to shinyServer | ||
#' @return An observer reference class object that is responsible for offering code completion. | ||
#' See \code{\link[shiny]{observe}} for more details. You can use \code{suspend} or \code{destroy} | ||
#' to pause to stop dynamic code completion. | ||
#' @export | ||
#' @export | ||
aceAutocomplete <- function(inputId, session = shiny::getDefaultReactiveDomain()) { | ||
shiny::observe({ | ||
value <- session$input[[paste0(inputId, "_hint")]] | ||
if(is.null(value)) return(NULL) | ||
value <- session$input[[paste0(inputId, "_shinyAce_hint")]] | ||
if (is.null(value)) return(NULL) | ||
|
||
utilEnv <- environment(utils::alarm) | ||
w32 <- get(".win32consoleCompletion", utilEnv) | ||
|
||
comps <- list(id = session$ns(inputId), | ||
codeCompletions = w32(value$linebuffer, value$cursorPosition)$comps) | ||
|
||
codeCompletions <- w32(value$linebuffer, value$cursorPosition$col)$comps | ||
codeCompletions <- strsplit(codeCompletions, " ", fixed = TRUE)[[1]] | ||
codeCompletions <- lapply(codeCompletions, function(completion) { | ||
list(name = completion, value = completion, meta = "R") | ||
}) | ||
|
||
comps <- list( | ||
id = inputId, | ||
codeCompletions = jsonlite::toJSON(codeCompletions, auto_unbox = TRUE) | ||
) | ||
session$sendCustomMessage('shinyAce', comps) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.