Reputation: 1490
I am using the Ace JavaScript editor with the vim keybindings. However, when I press the escape key (to get out of insert mode, for example), instead of getting me out of the mode, the editor un-focuses. What is the best way for me to capture this keypress in all modern browsers, and allow ace to use it?
To witness this problem, go here, turn on vim keys, and then try to enter and escape a mode. I'm running the latest version of Firefox.
Upvotes: 2
Views: 533
Reputation: 1490
Turning off the Vimium extension, which I had installed everywhere, worked. Sorry to everyone who spent their time on this...
Upvotes: 2
Reputation: 6912
Maybe attaching a keydown
event to the document could help?
If the key pressed is escape, call e.preventDefault
to prevent default browser behavior from happening.
$(document).on("keydown", function(e) {
if(e.key == "Escape") {
e.preventDefault();
console.log(e.key + " pressed");
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Upvotes: 0