-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Chrome][Safari][IME] Starting composition on non-collapsed selection containing partially styled element throws an error. #3080
Comments
Works fine on FF. On Chrome still behaves as described above. Safari seems to replace selection properly (resulting in |
Rechecked with https://github.com/ckeditor/ckeditor5-engine/issues/1417, still reproducible as described in the above comment. |
I checked what is the difference in a rendering flow when regular character
For regular character
For composition starting character
1. The So here basically rendering between handling mutations changes the DOM structure. The mutation which is processed as a second one contains reference to already detached DOM element which breaks whole flow. For now I see two possibilities:
WDYT @Reinmar? The first one should be easier, but it feels a little like a workaround not the direct cause fix. However, since we were thinking of working on it, maybe we can give it a try? |
Do I understand correctly that |
Well, it looks like. I mean, it does nothing because selection is collapsed in this case. So if it was the assumption that it will "remove" selection contents before composition is started then yes, it does not work. I wonder why selection is collapsed in this case, looking at events order, keydown should be handled first so selection still should be not affected by any composition mechanisms 🤔 |
It's worth reporting upstream. But we'll need to figure something out too. The idea was that we don't want to allow character insertion on a non collapsed selection because this may lead to a lot more mutations that we're able to handle. E.g. when blocks merge it's a disaster for us. Therefore, it would be great if there was some way to handle this also when composition starts. Can we do that on compositionstart itself? I guess not - because our DOM changes will break composition. So is there any other event?
…Sent from my iPhone
On 5 Jun 2018, at 17:50, Krzysztof Krztoń ***@***.***> wrote:
Do I understand correctly that _handleKeydown() doesn't work in this case? That's bad... It exactly the thing that was supposed to prepare the DOM for upcoming composition.
Well, it looks like. I mean, it does nothing because selection is collapsed in this case. So if it was the assumption that it will "remove" selection contents before composition is started then yes, it does not work. I wonder why selection is collapsed in this case, looking at events order, keydown should be handled first so selection still should be not affected by any composition mechanisms 🤔
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
This behaviour is somehow strange. I prepared a codepen to check on what events selection is still non-collapse. For regular typing and composition I get very similar results. For regular typing (boolean value after event type shows if selection is collapsed): and for Spanish accent: which means in our Which looks like So at least one of this things deserves an upstream (reported strange debugging sequnece). |
Ok, the cause is slightly different here 😬 Since while debugging, selection seems to be collapsed (because of some strange behaviour shown in the comment above) I thought this is the case here. However, when using good ol' So Btw. I did a super quick test and removing |
Try |
Yes, indeed 😅 One of the reasons is what I mentioned in a previous comment probably:
So I think the potential fix can work like:
From what I see (at least for Hiragana) |
So I went with the approach mentioned in the https://github.com/ckeditor/ckeditor5-typing/issues/83#issuecomment-395027323 above and it has some potential. I have implemented the fix and tested it on Chrome, Firefox and Safari with macOS accent panel, Spanish, Japanese (Hiragana) and Korean (2-Set) keyboards. It works fine on Chrome (which means fixes the issue) and Firefox. However, there are some issues on Safari - the order of events is different in some cases:
I think for Safari we may try one more think in the |
Checked and it removes also a character which started a composition 🤔 |
So the final solution I came up with works as follows:
This covers Chrome where events order is However, on Safari the order in most cases is
|
There is an issue in Edge browser. Composition there works slightly different:
I also noticed one issue on Chrome caused by the current implementation. When starting Japanese composition (only native macOS IME keyborad, works fine with Google ones and on Windows) over non-collapsed selection, you have to then press |
The problem in Chrome originates from the fact that after selection contents removal, selection is rerendered: however as DOM is modified it is necessary to update the selection, so I'm not sure yet if there is any reasonable workaround 🤔 As for Edge (tested with The one workaround I see is to adjust the current mechanism:
in a way that selection content is removed on |
So the above problem with Chrome is caused by the fact that whole text nodes gets replaced in the I did a quick check and fixing https://github.com/ckeditor/ckeditor5-engine/issues/1425 seems to help. |
I did a test on plain This is not identical behaviour to what happens in the editor (content is not removed directly, changes are passes through a model and then are rendered), but the end result is the same so it seems this is more native behaviour (I also checked it with quick-fix for ckeditor/ckeditor5-engine#1425 mentioned in the comment above, but it doesn't change anything). |
Some thoughts not directly connected with this issue, but more with a fix and how things works. W3 documentation describes
So clearing composition contents on |
I have reported the Edge issue https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/17997826/. ATM I'm not sure if it will be fixed by the browser vendor, because I haven't found a part describing this specific behaviour in any W3 specs, which may mean it is not an incorrect behaviour. Still, it works different/better in other browsers so I gave it a try. |
Fix: Remove selection contents on `keydown` before the composition starts. Closes #83. Closes #150. BREAKING CHANGE: `@ckeditor/ckeditor5-typing/src/changebuffer.js` was moved to `@ckeditor/ckeditor5-typing/src/utils/changebuffer.js';
<p><em>Th[is</em> is] an <strong>editor</strong> instance.</p>
.'
or Hiragana with e.g.a
).Chrome
The character starting the composition is inserted (marked as
X
below), but the resulting html is<p><em>ThX[]</em>] is an <strong>editor</strong> instance.</p>
, which means only styled part of the selection was replaced. Also an error is throwUncaught TypeError: Cannot read property 'parent' of null
.Safari
Resulting html is
<p><em>ThX[]s</em>] an <strong>editor</strong> instance.</p>
, no error thrown.The text was updated successfully, but these errors were encountered: