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

keyboard.addBinding for 13/Enter doesn't seem to have an effect #4247

Closed
ile opened this issue Jun 9, 2024 · 3 comments
Closed

keyboard.addBinding for 13/Enter doesn't seem to have an effect #4247

ile opened this issue Jun 9, 2024 · 3 comments

Comments

@ile
Copy link

ile commented Jun 9, 2024

Adding these in Playground doesn't seem to have an effect. Not sure if this is by design or not.

quill.keyboard.addBinding({
    key: 13,
    shiftKey: true,
    handler: (range, context) => {
        console.log(range, context);
    }
});

quill.keyboard.addBinding({
    key: 'Enter',
    shiftKey: true,
    handler: (range, context) => {
        console.log(range, context);
    }
});

I'm trying to add functionality for Shift+Enter, for adding a newline or <br>: #1187

If there is some way to accomplish the <br> that would be great as well.

@lkalinowski
Copy link

lkalinowski commented Jun 9, 2024

We asked for help with this also in this issue: #4228

In your case you should use anonymous function instead of arrow function. Example in quill docs: https://quilljs.com/docs/modules/keyboard

quill.keyboard.addBinding({
    key: 'Enter',
    shiftKey: true,
    handler: function(range, context) {
        console.log(range, context);
    }
});

P.S. Quite complex article about differences between arrow and classic functions: https://www.freecodecamp.org/news/the-difference-between-arrow-functions-and-normal-functions/

@ile ile changed the title addBinding for 13/Enter doesn't seem to have an effect keyboard.addBinding for 13/Enter doesn't seem to have an effect Jun 9, 2024
@ile
Copy link
Author

ile commented Jun 10, 2024

It doesn't make a difference if I use an anonymous function.13/Enter won't be caught.

@ile
Copy link
Author

ile commented Jun 23, 2024

I found the docs.

However since bindings specified in the configuration will run before Quill's defaults, you can handle special cases and propagate to Quill's otherwise.

@ile ile closed this as completed Jun 23, 2024
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