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

Accepting spellcheck suggestion deletes containing span #2527

Closed
szhu opened this issue Feb 28, 2019 · 13 comments
Closed

Accepting spellcheck suggestion deletes containing span #2527

szhu opened this issue Feb 28, 2019 · 13 comments

Comments

@szhu
Copy link

szhu commented Feb 28, 2019

This bug is rather specific but definitely reproducible and does happen in practice.

Steps for Reproduction

GIF of this happening:
screen recording 2019-02-28 at 02 31 pm

  1. Use Chrome.
  2. Create a new Google doc: https://docs.new
  3. Type in Sentence wthi a typo. Copy the sentence.
  4. Visit https://quilljs.com
  5. Paste.
  6. Wait for wthi to get a red underline. Then click it and accept the suggestion.

Expected behavior:
The suggestion should be selected.

Actual behavior:
The entire sentence is deleted. In the console:

addRange(): The given range isn't in document.
value @ selection.js:294
(anonymous) @ selection.js:48
o.emit @ index.js:151
value @ emitter.js:29
value @ scroll.js:162
(anonymous) @ scroll.ts:29

Platforms:
macOS Mojave, Chrome Version 73.0.3683.46 (Official Build) beta (64-bit)

Version:
1.3.6

@szhu
Copy link
Author

szhu commented Mar 6, 2019

I think I've narrowed down the issue. This is the more general case that always fails:

  1. Use Chrome.
  2. In Quill, add some text that meets these properties:
    • Has a span
    • Has a typo somewhere inside the span.
  3. Accepting the spellcheck will delete the entire span.

@szhu szhu changed the title Accepting spellcheck suggestion deletes text Accepting spellcheck suggestion deletes containing span Mar 6, 2019
@Amit-Gore
Copy link

I am facing the same problem while working with vue2-editor (quill based)

quill.formatText(offset, length, { 'color': 'red' })
Do you have any updates @szhu , did you manage to solve it ?

@szhu
Copy link
Author

szhu commented Aug 13, 2019

We actually did, but it's kind of hacky -- basically we "unwrapped" the spans (replaced the spans with their children). Two key observations:

  1. This will remove the styling that's set directly on the spans. For example, if you copy yellow text from Google Docs and use this fix, then the text will not be yellow anymore.
  2. A way to make this process involve as little manual DOM manipulation as possible is to simply clear the style attribute from the spans. Quill will automatically "unwrap" useless spans!

Here's our rough pseudocode:

  1. Listen for the the text-change event where the source is user (to prevent a feedback loop).

  2. Find all the spans that you're okay removing all styles from. Specifically, to solve just the Google Docs example above and to not do anything too aggressive, we used:

    quillContainer.querySelectorAll('span[style="background-color: transparent; color: rgb(0, 0, 0);"]')

    But you can select all spans if you want.

  3. For each of these results, clear their style attribute, i.e., element.removeAttribute("style").

@ruchira088
Copy link

Any updates on this issue?

@maniyadv
Copy link

I got this solved by formatting the pasted content to plaintext before spell check using -

quill.clipboard.addMatcher (Node.ELEMENT_NODE, function (node, delta) {
    var plaintext = node.innerText
    var Delta = Quill.import('delta')
    return new Delta().insert(plaintext)
})

Or use - https://www.npmjs.com/package/quill-paste-smart

@Nicholas-Westley
Copy link

Is there any update on this? Any idea where I would have to start looking in the quill codebase if I wanted to fix it?

@denishegarty
Copy link

Is there any update on this?

@sho13
Copy link

sho13 commented Feb 26, 2021

Hello, are there any updates on this?

@RyanLackie
Copy link

Hi, are there any updates on this bug?

@njtmead
Copy link

njtmead commented Apr 10, 2021

+1

@kenichi-ando
Copy link

This seems to be a duplicate of #2096.

@luin
Copy link
Member

luin commented Jul 30, 2023

👋 Sorry for the late update. This is fixed in #3807. Feel free to let me know if there is anything missing.

@luin luin closed this as completed Jul 30, 2023
@kenichi-ando
Copy link

kenichi-ando commented Jul 31, 2023

@luin Thank you for the update! Do you have any plans to release the new version including this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests