OscarGodson / EpicEditor

EpicEditor is an embeddable JavaScript Markdown editor with split fullscreen editing, live previewing, automatic draft saving, offline support, and more. For developers, it offers a robust API, can be easily themed, and allows you to swap out the bundled Markdown parser with anything you throw at it.
http://epiceditor.com
MIT License
4.25k stars 338 forks source link

How do we bind CMD+Enter or Ctrl+Return to epic editor? #373

Closed vviikk closed 9 years ago

vviikk commented 9 years ago
editor.on('keydown', function (e) {
        console.log(e);
        if (e.keyCode == 13 && (e.metaKey || e.ctrlKey)) {
            alert('test');
        }
    });

Doesn't seem to work

OscarGodson commented 9 years ago

Try something like

editor.getElement('editor').addEventListener('keydown',function (e) {
  console.log(e.keyCode)
})
OscarGodson commented 9 years ago

Check out the getElement docs on what elements you can bind to

vviikk commented 9 years ago

Apologies. I was doing it on the main editor element.

Here's my solution. Worked like a charm. Thanks.

    editor.getElement('editor').addEventListener('keydown',function (e) {
        if (e.keyCode == 13 && (e.metaKey || e.ctrlKey)) {
            $("#post-comment").click();
        }
    })