-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Keymaster not unbinding keypresses. #2758
Comments
Well, it works with other keymaps so I'd say it handles that option, but have no idea what is wrong with
Agree, but what about your case
yeah, I've noticed that too, but that might require a bit of work probably. Are you already aware of any good alternative? |
Man... I looked through Keymaster and that unbind function handles multiple keys, so the issue must be somewhere else. I didn't notice anything glaring when I looked. No errors show up when I try to unbind the key. I'm using GrapesJS in a single page app so I need to destroy GrapesJS and reinit it again without the browser reloading. This is how I found the bug initially. When you destroy, reinit, and use the delete or backspace keys, the callback is called on the original editor object and not the new one which throws an error. I'm running this before I call const keys = 'up, down, left, right, shift+up, shift+down, shift+left, shift+right, backspace';
keys.split(/, ?/).forEach((key) => {
this.editor.Keymaps.keymaster.unbind(key);
}); I've not used any key mapping plugins before, but I'd be more than happy with opening a PR. Are you good with the string split approach? Looks like Keymaster does the same thing i was doing. |
Sure, let's see if it works |
This is reproducible on the demo site running
0.16.12
.In the console, run
editor.Keymaps.removeAll()
and try to delete a component. It does delete the component, and I don't believe it should. It seems like the other Keymaps are unbinding fine.I'm not sure if this is an issue with grapesjs or keymaster. Noticed this when I was adding a custom keymap for the arrow keys and noticed it wasn't getting cleaned up when
editor.destroy()
was called.I did notice I could unbind the delete command like this:
I'm wondering if the unbind command in keymaster was meant to handle an individual key instead of multiple ones in the case of backspace but the copy/paste/undo/redo are working correctly.
Looks like a simple solution could be splitting
keymap.keys
string here and unbinding the keys individually. Also noticed keymaster hasn't been updated in a while so it might be worth switching it out. Willing to open a PR for this.The text was updated successfully, but these errors were encountered: