I need to build an editor that simulates a native input, so I need to prevent enter from being pressed and causing a newline. To prevent most characters I can just preventDefault on keydown if a disallowed character is pressed, but because I need to disallow enter I also need to delete quill.modules.keyboard.hotkeys[13], but that seems a little gross. Is there a better way to do this?
A removeHotkeys call was added by #453 but has not been released yet. Quill is in the middle of a big change so the next version will take much longer to get out. I was also considering changing the signature into removeHotkey and removeAllHotkeys to be more consistent with eventemitter APIs.
What's the correct way to do this in 1.X?
Previously quill.modules.keyboard.removeHotkeys({ key: 13 }); had worked. Disabling bindings works for keys such as tab. However I can't find a way to prevent handleEnter from occurring. The documentation suggests that it just straight up can't be done due to dangerous behaviour, though it could in 0.21 with seemingly no implications.
The documentation is correct. But I think there may be a misunderstanding. You can add a handler to run before the default and not propagate to handleEnter. What you cannot do, which is the dangerous thing, is prevent handleEnter from running in order for the browser default behavior to run.
Thanks @jhchen, the following worked just fine to prevent a new line and tab space
keyboard: {
bindings: {
tab: false,
handleEnter: {
key: 13,
handler: function() {
// Do nothing
}
}
}
}
How do you prevent/remove newlines when pasting in content?
Hello, I stumbled upon a particular behavior while trying to disable the enter key in Quill. The snippet suggested by @Joeao works fine until you pass to a heading format.
In that case the editor will ignore the disabling and insert a new line.
Any suggestions in order to fix this issue?
Most helpful comment
Thanks @jhchen, the following worked just fine to prevent a new line and tab space