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

Listener for cursor changes and key presses #14

Closed
skranz opened this issue Aug 25, 2014 · 2 comments
Closed

Listener for cursor changes and key presses #14

skranz opened this issue Aug 25, 2014 · 2 comments

Comments

@skranz
Copy link
Contributor

skranz commented Aug 25, 2014

Dear Jeff,

thanks for creating shinyAce, it is a great and useful package. For an application I needed listeners that can react to key presses and cursor changes. I forked your shinyAce into

https://github.com/skranz/shinyAce

and added that functionality by adding arguments cursorId and keyId, which work similar as your selectionId argument. I also changed the generated javascript code in aceEditor by naming differnent editors with the variable editorVar. This is neccessary for cursor and key events to work correctly when there are multiple aceEditors.

Here is a sample code that uses the new functioniality:

library(shiny)
library(shinyAce)

keys = list(runLineKey="Ctrl-Enter", helpKey="F1", runKey="Ctrl-R|Ctrl-Alt-R", hintKey="Ctrl-H")
ui = bootstrapPage(
  aceEditor("ace",value="text1\nline2", height=100,
            keyId=keys, showLineNumbers=FALSE,highlightActiveLine=FALSE, cursorId="mycursor")
  ,aceEditor("ace2",value="text2", height=100,keyId=keys)
)

server = function(input, output, session) {
  observe({
    cat("Cursor changed:")
    print(input$mycursor)
  })
  observe({
    cat("\nrunLineKey pressed:")
    print(input$runLineKey)
  })
  observe({
    cat("\nhelpKey pressed:")
    print(input$helpKey)
  })

}

runApp(list(ui=ui, server=server), launch.browser=rstudio::viewer)

If you like the new functionality, I am very happy to merge the new version with your shinyAce version. (I have never performed a pull request, but I guess that is not so complicated).

Best wishes,
Sebastian

@trestletech
Copy link
Owner

Hi Sebastian. Sorry to just now get to this.

This might actually pertain to another issue that was opened: #15

This definitely looks like useful functionality. I may end up wanting to nit pick some of the details before we merge it in, but these features could certainly be candidates for inclusion in the package. Feel free to open a PR and I'll do a more thorough review of the code to see what I'd ask for before we merge.

Hopefully I'll get to the review in a more timely manner :)

Thanks for offering the code up! Hopefully we can get it into the project so others can benefit.
Jeff

@vnijs
Copy link
Collaborator

vnijs commented Oct 13, 2014

That looks great! Was this implemented already? I assume it is also configurable for Mac? Thanks @skranz and @trestletech!

A shortcut key for spelling (#17) would be amazing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants