Switching tabs by pressing the ctrl or metakey, then clicking back to sir trevor tab causes pressing 'b' key to turn on bold
tiffanywei opened this issue · 0 comments
tiffanywei commented
This happened in my project where if someone has the text block focused and then switches tabs by using a shortcut with the ctrl or metakey (eg ctrl + tab in chrome) and switches back to the Sir Trevor tab by clicking on the tab, Sir Trevor will register the keydown
event, but not the keyup
event, thus the ctrlDown
state in src/block.js
stays true
and if the next keydown is a command keycode, it will execute that command.
This can be reproduced in the Sir Trevor docs example.
http://madebymany.github.io/sir-trevor-js/example.html
- Focus on a text block.
- ctrl + tab to switch tabs
- click back on the original tab
- press the 'b' key
- typing more keys will be in bold
I fixed this in my project by replacing lines src/block.js:367-383
with
Events.delegate(block.el, '.st-text-block', 'keydown', function (ev) {
if ((ev.metaKey || ev.ctrlKey) && ev.keyCode === cmd.keyCode) {
ev.preventDefault();
block.execTextBlockCommand(cmd.cmd);
}
});
Should I open a PR for this?