kazzkiq / CodeFlask

A micro code-editor for awesome web pages.
https://kazzkiq.github.io/CodeFlask/
MIT License
1.07k stars 120 forks source link

add custom event listener option #122

Open acarl005 opened 4 years ago

acarl005 commented 4 years ago

As discussed in issue #123, this PR add a new option to the CodeFlask constructor: customEventListeners.

customEventListeners is an object where the keys are the event names and the values are the callbacks for the event. This is an example of using this option to implement a hotkey like cmd+enter which doesn't cause a newline to get added to the content of the editor.

      flask = new CodeFlask(editor, {
        customEventListeners: {
          "keydown": e => {
            if (e.key == "Enter" && e.ctrlKey) {
              e.preventDefault()
              e.stopImmediatePropagation()
              // trigger hotkey
            }
          }
        }
      })