slab / quill

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

Update modules without re-instantiating the editor? #4234

Open ViktorZhurbin opened 1 month ago

ViktorZhurbin commented 1 month ago

Question: Do I have to create a new Quill instance to update modules? Or is there a way to update them directly, something like:

const quill = new Quill(editorContainer, {
  modules, // <- this can change
  theme: "snow",
 });

// later on
quill.options.modules = updatedModules. // doesn't work, obviously

Context: I need to override some default keyboard bindings, and I do it through the config as suggested. When a binding needs to be updated (eg, user can change it in settings), it looks like I need to create a new Quill instance with updated config. This creates an extra hustle of saving/re-applying existing user input and selection.

luin commented 1 month ago

One approach would be updating quill.keyboard.options directly so in binding handlers, you could read the options dynamically

ViktorZhurbin commented 1 month ago

One approach would be updating quill.keyboard.options directly so in binding handlers, you could read the options dynamically

Typescript would not be happy about it. There's probably a reason for this property to be protected:

Property 'options' is protected and only accessible within class 'Module<T>' and its subclasses
Screenshot 2024-06-04 at 08 46 47
ViktorZhurbin commented 1 month ago

I opened #4237 which seems like a separate bug to me. I wouldn't hit it, if I didn't have to re-create the editor. But it's still a bug on its own.