patleeman/quill-markdown-shortcuts

Cannot remove formatting at the begining of the text

Betree opened this issue · 2 comments

Hey there! Great project, the user experience is really good.

I have a small issue: when adding formatting (quote, title...etc) at the beginning of the text, it cannot be removed by pressing backspace key. See screencast below.

Peek 16-05-2019 21-18

Thanks for the report.

I agree this is not great. I haven't had much time to work on this module and I don't use Quill in any active projects so I haven't had much need to fix this. If anybody would like to take a crack at it and submit a PR i can review and publish. I'll leave this issue open in case anybody wants to try.

@patleeman @Betree

I find a way to make this work, but from outside this markdown modules.
Register a keyboard module on quill modules like this:

modules: {
  toolbar: {},
  markdownShortcuts: {},
  keyboard: {
    bindings: {
      custom: {
        key: 'backspace',
        format: ['blockquote', 'header'], // need to put all possibilities here
        handler: function(range, context) {
          if (context.offset === 0) {
            // When backspace on the first character of a format,
            // remove the format instead
            this.quill.format(Object.keys(context.format)[0], false, Quill.sources.USER);
          } else {
            // Otherwise propagate to Quill's default
            return true;
          }
        }
      }
    }
  }
}

If I put that inside MarkdownShortcuts constructor using this.quill.keyboard.addBinding() it doesn't work.

Source: https://quilljs.com/docs/modules/keyboard/#configuration