patleeman / quill-markdown-shortcuts

Quill.js module that converts markdown to rich text formatting while typing.
https://patleeman.github.io/quill-markdown-shortcuts/
140 stars 49 forks source link

Cannot remove formatting at the begining of the text #24

Open Betree opened 5 years ago

Betree commented 5 years ago

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

patleeman commented 5 years ago

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.

laurensiusadi commented 5 years ago

@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