Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add word wrap feature #12

Merged
merged 1 commit into from
Apr 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}