Skip to content
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

Closed
mattdeigh opened this issue May 7, 2020 · 3 comments
Closed

[BUG] Keymaster not unbinding keypresses. #2758

mattdeigh opened this issue May 7, 2020 · 3 comments

Comments

@mattdeigh
Copy link
Contributor

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:

editor.Keymaps.keymaster.unbind('backspace');
editor.Keymaps.keymaster.unbind('delete');

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.

@artf
Copy link
Member

artf commented May 15, 2020

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.

Well, it works with other keymaps so I'd say it handles that option, but have no idea what is wrong with backspace, delete (with delete, backspace it even raises an error ???)

Looks like a simple solution could be splitting keymap.keys string here and unbinding the keys individually

Agree, but what about your case I was adding a custom keymap for the arrow keys? Does it work with the split? The PR is super welcome :)

Also noticed keymaster hasn't been updated in a while so it might be worth switching it out

yeah, I've noticed that too, but that might require a bit of work probably. Are you already aware of any good alternative?

@mattdeigh
Copy link
Contributor Author

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 editor.destroy() and it seems to work fine. Have no idea why Keymaster isn't working.

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.

@artf
Copy link
Member

artf commented May 15, 2020

Are you good with the string split approach?

Sure, let's see if it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants