madebymany/sir-trevor-js

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

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

  1. Focus on a text block.
  2. ctrl + tab to switch tabs
  3. click back on the original tab
  4. press the 'b' key
  5. 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?