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

editor.keyboard.add Binding Backspace execution is not expected #4115

Open
boomsi opened this issue Apr 16, 2024 · 0 comments
Open

editor.keyboard.add Binding Backspace execution is not expected #4115

boomsi opened this issue Apr 16, 2024 · 0 comments

Comments

@boomsi
Copy link

boomsi commented Apr 16, 2024

Steps for Reproduction

  1. Visit [quilljs.com, jsfiddle.net, codepen.io]
  2. Step Two
  3. Step Three
editor.keyboard.addBinding({
      key: "Backspace",
      handler: function (range) {
        console.log("Custom backspace handler");
        console.log(range);
        if (range.length > 0) { // Never execute!!!
          // If text is selected, apply red color to the selection instead of deleting
          editor.formatText(range.index, range.length, "color", "red");
        } else {
          // If no text is selected, apply red color to the character before the cursor
          let format = editor.getFormat(range.index - 1, 1);
          if (format.color === "red") {
            // If already red, remove it (toggle behavior)
            editor.formatText(range.index - 1, 1, "color", false);
          } else {
            // Apply red color
            editor.formatText(range.index - 1, 1, "color", "red");
          }
        }

        return false; // Do not delete the character/text
      },
    });

Expected behavior:

All backspace events are captured

Actual behavior:

It is captured only if there is no check, and the handler is not executed if there is a check.

Platforms:

MacOS: 13.4.1
Chrome: "123.0.6xxxx"
"quill": "2.0.0-rc.5"
"React": "18.2.0"

Include browser, operating system and respective versions

Version:

Run Quill.version to find out

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

1 participant