aceEditor bugs when initialized with certain escape characters (\r & \f)
The-Dub opened this issue · 2 comments
Hi,
I realized that the aceEditor
function breaks when you initialize the value
parameter with \r or \f. The later also breaks RStudio a little bit (clears the console). I tried the other common escape characters, and it worked fine.
> aceEditor('foobar', 'foo') # works fine
<pre id="foobar" class="shiny-ace" style="height: 400px"></pre>
<script type="text/javascript">var editor__foobar = ace.edit('foobar');editor__foobar.setValue("foo", -1);document.getElementById('foobar').style.fontSize='12px'; $('#foobar').data('debounce',1000);$('#foobar').data('aceEditor',editor__foobar);</script>
> aceEditor('foobar', 'foo\r')# the javascript is messed up
<pre id="foobar" class="shiny-ace" style="height: 400px"></pre>
", -1);document.getElementById('foobar').style.fontSize='12px'; $('#foobar').data('debounce',1000);$('#foobar').data('aceEditor',editor__foobar);</script>
> aceEditor("foobar", "foo\f") # the console clears in RStudio and the javascript is probably also messed up
I looked at the code, and I believe it's coming from the jsQuote function
jsQuote <- function(text){
toReturn <- shQuote(text)
toReturn <- gsub('\n', '\\\\n', toReturn)
toReturn
}
I changed the function by adding two exceptions handlers for \r and \f, and it seems to fix the aceEditor function.
jsQuote <- function(text){
toReturn <- shQuote(text)
toReturn <- gsub('\n', '\\\\n', toReturn)
toReturn <- gsub('\r', '\\\\r', toReturn)
toReturn <- gsub('\f', '\\\\f', toReturn)
toReturn
}
> aceEditor2("foobar", "foo\r")
<pre id="foobar" class="shiny-ace" style="height: 400px"></pre>
<script type="text/javascript">var editor__foobar = ace.edit('foobar');editor__foobar.setValue("foo\r", -1);document.getElementById('foobar').style.fontSize='12px'; $('#foobar').data('debounce',1000);$('#foobar').data('aceEditor',editor__foobar);</script>
> aceEditor2("foobar", "foo\f")
<pre id="foobar" class="shiny-ace" style="height: 400px"></pre>
<script type="text/javascript">var editor__foobar = ace.edit('foobar');editor__foobar.setValue("foo\f", -1);document.getElementById('foobar').style.fontSize='12px'; $('#foobar').data('debounce',1000);$('#foobar').data('aceEditor',editor__foobar);</script>
I don't have an extended knowledge of the code behind the scene to know if it could create problem somewhere else though ... 😮
Hey Jeff (@trestletech)
What is the chance of this change getting incorporated into shinyAce? Would it help if I sent you a PR? The reason I'm asking is because I'm certain this issue is causing problems for my swirlify package (swirldev/swirlify#37). If there's any way I can help get this resolved quickly please let me know, I know you're a busy man.
Sean
@The-Dub and @seankross Please install the development version of shinyAce using devtools::install_github("trestletech/shinyAce") and try it out. Should address the identified issue