sparksuite / simplemde-markdown-editor

A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://simplemde.com
MIT License
9.79k stars 1.12k forks source link

how to define a shortcuts then call my function #710

Closed zuiwuchang closed 5 years ago

zuiwuchang commented 5 years ago

i want to press `ctrl+s` call my function on SimpleMDE has focus how do it?

// my func work on `ctrl+s`
function ShortcutsTest(){
  console.log("it work")
}

new SimpleMDE({
  shortcuts: {
        "toggleOrderedList": "Ctrl-Alt-K", // alter the shortcut for toggleOrderedList
        "toggleCodeBlock": null, // unbind Ctrl-Alt-C
        "drawTable": "Cmd-Alt-T", // bind Cmd-Alt-T to drawTable action, which doesn't come with a default shortcut

        "XXXX":"Cmd-S" // ? How to make her work call function ShortcutsTest
    }
})
zuiwuchang commented 5 years ago

i get it

const mde = new SimpleMDE({})
const codemirror = mde.codemirror;
// get shortcuts list
const keys = codemirror.getOption("extraKeys");
// add own's ...
keys["Ctrl-S"] = () => { //work on 'ctrl+s'
      console.log("it work")
};
// update shortcuts list
codemirror.setOption("extraKeys", keys);
JornahLee commented 2 years ago

nice! thanks for your answer!