From 479982ce196a13ab3faf31e33e45f21226d34c46 Mon Sep 17 00:00:00 2001 From: Nick Carchedi Date: Mon, 14 Apr 2014 22:18:00 -0400 Subject: [PATCH] add word wrap feature --- R/ace-editor.R | 7 ++++++- R/update-ace-editor.R | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/R/ace-editor.R b/R/ace-editor.R index fa84bbe..40ba9b9 100644 --- a/R/ace-editor.R +++ b/R/ace-editor.R @@ -17,6 +17,8 @@ #' "\code{auto}"). #' @param fontSize Defines the font size (in px) used in the editor and should #' be an integer. The default is 12. +#' @param wordWrap If set to \code{TRUE}, Ace will enable word wrapping. +#' Default value is \code{FALSE}. #' @import shiny #' @examples \dontrun{ #' aceEditor("myEditor", "Initial text for editor here", mode="r", @@ -26,7 +28,7 @@ #' @export aceEditor <- function(outputId, value, mode, theme, readOnly=FALSE, height="400px", - fontSize=12){ + fontSize=12, wordWrap=FALSE){ js <- paste("var editor = ace.edit('",outputId,"');",sep="") if (!missing(theme)){ js <- paste(js, "editor.setTheme('ace/theme/",theme,"');",sep="") @@ -44,6 +46,9 @@ aceEditor <- function(outputId, value, mode, theme, js <- paste(js, "document.getElementById('",outputId,"').style.fontSize='", as.numeric(fontSize), "px'; ", sep="") } + if (wordWrap){ + js <- paste(js, "editor.getSession().setUseWrapMode(true);", sep="") + } js <- paste(js, "$('#", outputId, "').data('aceEditor',editor);", sep="") tagList( diff --git a/R/update-ace-editor.R b/R/update-ace-editor.R index 3cc38e5..9bb0eea 100644 --- a/R/update-ace-editor.R +++ b/R/update-ace-editor.R @@ -15,6 +15,8 @@ #' If \code{FALSE} (the default), it will enable editing. #' @param fontSize If set, will update the font size (in px) used in the editor. #' Should be an integer. +#' @param wordWrap If set to \code{TRUE}, Ace will enable word wrapping. +#' Default value is \code{FALSE}. #' @examples \dontrun{ #' shinyServer(function(input, output, session) { #' observe({ @@ -26,7 +28,7 @@ #' @author Jeff Allen \email{jeff@@trestletech.com} #' @export updateAceEditor <- function(session, editorId, value, theme, readOnly, mode, - fontSize){ + fontSize, wordWrap){ if (missing(session) || missing(editorId)){ stop("Must provide both a session and an editorId to update Ace.") } @@ -48,6 +50,9 @@ updateAceEditor <- function(session, editorId, value, theme, readOnly, mode, if (!missing(fontSize)){ theList["fontSize"] <- fontSize } + if (!missing(wordWrap)){ + theList["wordWrap"] <- wordWrap + } session$sendCustomMessage("shinyAce", theList) } \ No newline at end of file