From 062a33fbc367658865434a089217ae36dd781ef8 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Mon, 18 Sep 2023 15:52:13 +0300 Subject: [PATCH] fix: workaround disappearing text on spellcheck suggestion --- .../src/vaadin-rich-text-editor.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/rich-text-editor/src/vaadin-rich-text-editor.js b/packages/rich-text-editor/src/vaadin-rich-text-editor.js index bf74094f35..540518d0d7 100644 --- a/packages/rich-text-editor/src/vaadin-rich-text-editor.js +++ b/packages/rich-text-editor/src/vaadin-rich-text-editor.js @@ -26,6 +26,35 @@ registerStyles('vaadin-rich-text-editor', richTextEditorStyles, { moduleId: 'vaa const Quill = window.Quill; +// Workaround for text disappearing when accepting spellcheck suggestion +// See https://github.com/quilljs/quill/issues/2096#issuecomment-399576957 +const Inline = Quill.import('blots/inline'); + +class CustomColor extends Inline { + constructor(domNode, value) { + super(domNode, value); + + // Map properties + domNode.style.color = domNode.color; + + const span = this.replaceWith(new Inline(Inline.create())); + + span.children.forEach((child) => { + if (child.attributes) child.attributes.copy(span); + if (child.unwrap) child.unwrap(); + }); + + this.remove(); + + return span; // eslint-disable-line no-constructor-return + } +} + +CustomColor.blotName = 'customColor'; +CustomColor.tagName = 'FONT'; + +Quill.register(CustomColor, true); + const HANDLERS = [ 'bold', 'italic',