kazzkiq / CodeFlask

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

Option to add custom event listeners to the CodeFlask textarea #123

Open acarl005 opened 4 years ago

acarl005 commented 4 years ago

Hello, I really like this library for it's small size. I was hoping to be able to add hotkeys to my editor, e.g. ctrl+enter to "execute" code. I tried to implement this by adding a "keydown" listener on the textarea generated by codeflask, but I was unable to prevent a newline from being inserted to the code due to the default behavior of the enter key. I tried, e.preventDefault(), but that was insufficient. Apparently I need to stop the "keydown" listener that codeflask added in order to prevent that. This is possible using e.stopImmediatePropagation(), but only if I call that method from an event handler that triggers before the other one. Since event handlers are triggered in the order they are added, this is impractical for the user. It would be nice if the CodeFlask constructor provided a way for users to add custom event handlers before the ones added by the library. I propose an implementation in my pull request #122 which allowed me to implement my hotkey. Please let me know if this is a welcome feature. I'm happy to help design this.

acarl005 commented 2 years ago

I forked it, added the option, and published under my namespace for now. Let me know if you want to merge.

https://github.com/acarl005/CodeFlask