Open winhamwr opened 8 years ago
I was able to reproduce this by just typing at my normal speed. No navigation necessary. In the paragraph I just typed, it happened with 3 different words: "squashing", "will", and "improvements"
The typo mark appeared while I was still in the middle of typing each word, so it feels like some sort of timing issue. Maybe if a spellcheck request/response goes fast enough that I didn't have enough time to add additional letters to the partial word, this happens (since adding letters would have changed the word, confusing the code that tries to mark it as a typo)? With the typo for "will", I definitely paused between typing the "wil" and the "l" because I was considering an alternative wording.
<p>Twice per month, the Flex Engineer will dedicate an entire day to <span class="nanospell-typo">squ</span>ashing usability issues. Our User Experience Design Lead, Jana, <span class="nanospell-typo">wil</span>l determine the priority and the focus will be on high-impact, low-effort <span class="nanospell-typo"><span class="nanospell-typo"></span><span class="nanospell-typo">improv</span>ements</span>. </p>
"improvements" started out by just marking "improv" as a typo (which is where I was at the time). I finished the word, typed some other stuff that I deleted, and then backspaced into the word to add a period. That seemed to trigger the remaining "ements" section being marked as a typo.
This was all using Chrome. I can try to reproduce by using another browser to editor next time, if that will help. Just let me know which browser to try.
Hmm. I don't think we need other browsers, though I will need to look into this bug. Spans are supposed to be removed on the current word, but maybe there is an order of events that is wrong here.
Interesting.
Seems like the span is not being removed on typing if you never leave the word. Probably because the cursor is outside of the span.
If you press enter on a block, it seems to fix this.
Argh.
It does not "fix" it actually, it marks it correctly but you can't click on the correct thing.
Possibly a side effect or an unfixed instance of #25 which also nested spellcheck spans.
Actually, the partial marking is the step before you end up into a similar state to what #25 fixed.
Plan for a repro test:
part 1
part 2
not sure yet, need to figure out why the span is not being ignored. maybe make a safety check where we clear any spans within the current word range, first.
For case 1, we don't have a good way to pause when typing has begun, but before spellcheck goes. hm.
I suspect the clearing not working is because it is:
<span class="nanospell-typo">qui</span>^
and not
<span class="nanospell-typo">qui^</span>
Very strange thing. Now I cannot reliably reproduce this.
Some of this weirdness has something to do with the cache.
If I get "sho" into the cache as a typo, it becomes impossible to type "shouldn't without the first 3 getting marked as typo, super quickly.
The cache just makes it worse, because once you get one bugged typo, it then guarantees that you'll see it for repeated words. Fix the original problem and it seems like the cache will fix itself.
So here is why it happens:
We changed things in #16 so that the walker just ignores spans, assumption being that if something is already a typo, we don't care.
What this does not account for, is where you add things onto the span afterwards.
Possible fixes
The test shows this:
Clearing the spans properly might be the correct thing to do, but it's unclear where and whether all possibly cases can be easily handled.
For example:
<p>qui^</p>
then paste
ly </p><p>some other paragraph</p>
The cursor will end up in the second paragraph and it won't be obvious that you have to go back and fix some previous paragraph tag. There doesn't seem to be a common sense way to do this from the generic change event so we'd probably need to handle all sorts of stuff I haven't thought of yet.
Quicker fix seems to be : revert the changes to not re-check already marked spans + make it so already marked spans cannot be remarked
Multi-span thing that causes problems - we shrink the range to only have the text, but we need to clean up the leftover span afterwards.
Other ugly case
Potentially you could have multiple typos being joined. for ex:
<span>foo</span> ^<span>bar</span>
, hit backspace.
That one is probably a whole other mess though.
What we should do:
remove spellcheck spans within the word range, but not do anything if the span already wraps the whole word.
Before shrinking the range to mark text, first check if the range covers an existing typo span. (this is tricky, need to confirm if the ranges include existing spans, or end inside them)
If so, do nothing, else clear any ranges within + mark the range.
notes on Trying the "ignore the current word" approach:
<b>foooooooooooooo</b>as^df<em>barrrrrrrrr</em> hello
)after having stepped back, it's quite annoying that you seemingly can't convert CKEditor ranges to w3c spec ranges. Because at least according to MDN, https://developer.mozilla.org/en-US/docs/Web/API/Range/compareBoundaryPoints would have been very useful
Tried moving some of the existing typo skipping back into the wordwalker.
This then led to another degenerate case around range.optimize():
<li><span>typozzz</span></li>
will optimize to contain the entire list item, which then means you end up having to find all spans within it and remove them anyway. So this kinda sucks. Back to having the word walker return everything and then fix/ignore existing typos later on.
various bad approaches later (and a lot of weird edge cases), attempt to filter the fragment before re-inserting.
That failed, because the fragment doesn't actually contain CKEditor nodes, but we can just as well remove spelllcheck spans from the spellcheck span. Why didn't I think of that earlier.
w3c spec ranges
Abandon all hope, ye who enter here. Every browser has a slightly different implementation of this spec. It really sucks.
Abandon all hope, ye who enter here. Every browser has a slightly different implementation of this spec. It really sucks.
Yea, I spent about 10 mins reading it and noped out.
I did some editing today and noticed that on at least two occasions, spellcheck marked a word as a typo because it chopped my word. I'm working on the exact reproduction steps, but it was while I was just typing up new content and using my keyboard to navigate around and edit it.
Example 1
Example 2
"keep" was split into "kee" and "p", but "p" wasn't marked as a typo.