Skip to content

Commit

Permalink
add word wrap feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarchedi committed Apr 15, 2014
1 parent e352ea4 commit 479982c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion R/ace-editor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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="")
Expand All @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion R/update-ace-editor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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.")
}
Expand All @@ -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)
}

0 comments on commit 479982c

Please sign in to comment.