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

What is the best way to disable a certain key? #479

Closed
jaketodaro opened this issue Sep 14, 2015 · 10 comments
Closed

What is the best way to disable a certain key? #479

jaketodaro opened this issue Sep 14, 2015 · 10 comments

Comments

@jaketodaro
Copy link

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?

@jhchen
Copy link
Member

jhchen commented Sep 14, 2015

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.

@jhchen jhchen closed this as completed Sep 14, 2015
@Joeao
Copy link
Contributor

Joeao commented Nov 1, 2016

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.

@jhchen
Copy link
Member

jhchen commented Nov 1, 2016

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.

@Joeao
Copy link
Contributor

Joeao commented Nov 2, 2016

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
            }
        }
    }
}

@BennieCopeland
Copy link

How do you prevent/remove newlines when pasting in content?

@l4nz10
Copy link

l4nz10 commented Jan 16, 2019

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?

@WilliamIPark
Copy link

@l4nz10 You've probably solved this by now, but I landed here with the same problems. Just to help anyone else who lands here in the future, this disables enter for headers & paragraphs:

keyboard: {
      bindings: {
        handleEnter: {
          key: 13,
          handler: () => {},
        },
        "header enter": {
          key: 13,
          handler: () => {},
        },
      },
    },

@hosnyben
Copy link

@l4nz10 You've probably solved this by now, but I landed here with the same problems. Just to help anyone else who lands here in the future, this disables enter for headers & paragraphs:

keyboard: {
      bindings: {
        handleEnter: {
          key: 13,
          handler: () => {},
        },
        "header enter": {
          key: 13,
          handler: () => {},
        },
      },
    },

You saved me vafter three misirable days of figuring out how to. Thank you Sir !

@mind-jayesh2401
Copy link

on Key press of 'enter' i have prevent from breaking line but when i search quill-emoji and try to press that is even stopped now because it's a part of quill editor and emoji selection is causing problem.

any suggestion how to do by quill methods ??
else i can do it by patch but i need solution in binding method itself.

@Masam-abbas-avialdo
Copy link

@mind-jayesh2401 Can you please tell me how to prevent line break. I am using ReactQuill in Nextjs App.

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

9 participants