Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: workaround disappearing text on spellcheck suggestion #6507

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/rich-text-editor/src/vaadin-rich-text-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <font> 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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you comment out this line, you'll notice that the DOM node is originally a <font> element, inserted by the browser spellcheck functionality exactly as described in slab/quill#2096 (comment).

Screenshot 2023-09-18 at 15 54 59


return span; // eslint-disable-line no-constructor-return
}
}

CustomColor.blotName = 'customColor';
CustomColor.tagName = 'FONT';

Quill.register(CustomColor, true);

const HANDLERS = [
'bold',
'italic',
Expand Down