slab / quill

Quill is a modern WYSIWYG editor built for compatibility and extensibility
https://quilljs.com
BSD 3-Clause "New" or "Revised" License
43.71k stars 3.4k forks source link

Question: custom dropdown scenario #1439

Closed Myrmex closed 7 years ago

Myrmex commented 7 years ago

This is probably more an issue of mine, but I'm posting here also because it might help authors figure out specific requirements coming from specific usages of this wonderful editor, and I'd really love to use Quill but I'm finding it difficult to customize it for my needs.

In my scenario, I'd need a dropdown in the toolbar, listing a variable number of programmatically defined entries, each with its own name, and a color to be applied to the current selection when clicked. Some of these entries would be linked to hotkeys, too. All these parameters vary as they come from an external source, and should be configured programmatically.

Just as a fake sample, think of an entry named "emphasis", which applies red color to the selected text, and maybe is bound to a shortcut like Windows Ctrl+E. I'll have some 10-30 entries like this, externally defined, and to be programmatically set into the editor.

As for the hotkeys, this seems easy: I can just add a new binding to the keyboard module (quill.keyboard.addBinding), bound to a function which formats the text with a specified color (this.quill.formatText), as per documentation (https://quilljs.com/docs/modules/keyboard/).

Yet, I'd need to make a dropdown with the full list of color-related entries, and here I'm a bit confused as, despite the Quill's extensibility (which for me would be the best reason for preferring it over all the other rich text editors), this does not seem a trivial task:

Could anyone help me figuring the best way of accomplishing this using Quill? Thanks!

jhchen commented 7 years ago

You do not have to do all of this within Quill. I would suggest just building this custom control separately and use Quill's APIs like formatText when the user selects a color.