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

Key listener for Tab doesn't work #1967

Closed
moonpatroller opened this issue Feb 16, 2018 · 6 comments · May be fixed by #2310
Closed

Key listener for Tab doesn't work #1967

moonpatroller opened this issue Feb 16, 2018 · 6 comments · May be fixed by #2310

Comments

@moonpatroller
Copy link

moonpatroller commented Feb 16, 2018

Please describe the a concise description and fill out the details below. It will help others efficiently understand your request and get to an answer instead of repeated back and forth. Providing a minimal, complete and verifiable example will further increase your chances that someone can help.

Steps for Reproduction

                editor.keyboard.addBinding({
                    key: 'Tab'
                }, function(range, context) {
                    console.log("HELLO");
                });

Expected behavior:
That code doesn't print to the console. Changing 'Tab' to 9 or '9' doesn't work. It does work for other keys.

Actual behavior:
That code should print to the console.

Platforms:

Mac 10.13.3 (17D47) and Chrome Version 64.0.3282.167 (Official Build) (64-bit)

Version: 1.3.5

It appears as though a pre-existing handler runs first and prevents my handler from running. Is there a way to put my handler first?

@moonpatroller
Copy link
Author

This appears to work:

editor.keyboard.bindings[9].unshift({
key: 9,
handler: function(range) {
console.log('user hit tab');
return true;
}
});

@DmitrySkripkin
Copy link

It appears as though a pre-existing handler runs first and prevents my handler from running. Is there a way to put my handler first?

Yes. You can overwrite the default binding, problem is you can't do with addBinding() but only with configuration just like this docs example: Keyboard Module configuration

@moonpatroller
Copy link
Author

@DmitrySkripkin When I use the example you pointed to it prevents the tab character from appearing in the quill editor or it prevents anything from happening at all, depending on whether I return true or not. Is there a way to get the default behavior, where the tab appears in the editor, but my code also runs?

@DmitrySkripkin
Copy link

DmitrySkripkin commented Feb 21, 2018

I dig a bit deeper. Default tab handler does not return anything. So even if you add a new binding it won't be executed anyway.

This means you have to rewrite it - basically copy/paste it or use method with unshift() you mentioned above.

P.S. Quill is not perfect, I would like to have more flexible bindings with some kind of weights to sort them.

@DanielKucal
Copy link

The problem is key has to be a number... It's even against type declared in @types/quill

@quill-bot
Copy link

Quill 2.0 has been released (announcement post) with many changes and fixes. If this is still an issue please create a new issue after reviewing our updated Contributing guide 🙏

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

Successfully merging a pull request may close this issue.

4 participants