-
-
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
Selection in Mutation #3699
Comments
There are more and more cases in which it will be tricky to predict where the selection should be put. The simplest case is: |
Actually, when you type the second space one of them is usually turned into Plus, of course, this is not only about spaces, but about all possible repeated characters. |
This is why we should fix https://github.com/ckeditor/ckeditor5-engine/issues/379 too. |
From what I take after toying a bit with The only problem with this approach is Modifying So it's a shame that we can't use tools that are already working, but I'd rather not modify I wonder which solution (of those three) is safest and cleanest, but it's probably best to go with DOM->View Selection mapping (if it's possible). If not that, we would need to check DOM Selection, whether it is collapsed or not and either pass it do |
Modifying diff gives us nothing. You will never know if it was a first or a second letter inserted using only diff. You need DOM Selection to handle it. |
Maybe prematurely, but I don't like the idea with not setting the selection. It forces us to base on the assumption that last change in the content is the right place for the caret. This is plainly wrong in cases like autocompletion or spellchecker where the middle letter of a word may be replaced by the browser while the selection should be (usually) after this word. BTW, there's one related thing that came to my mind some time ago. Right now we use the sneaky snaky diff algorithm which gives us the minimal set of changes which need to be done to the content. For example, when we're replacing word "bafferr" with "buffer", according to this algorithm, we make two changes: Based on mutations we won't be able to understand the semantics correctly, but at least we could say that we replace "affer" with "uffe" (so – the change is between the first and last changed piece). Thanks to that the input feature would make one change in the model instead of two and this is a lot better when you look at this from the You can ask, why do we use the OTOH, we'll still have to use the PS. I thought about the |
Let me clarify.
As I hinted, modifying As I said, this stinks and I want to avoid such solution. We could, however, change/remove
I am not sure what you are writing about and whether you understood the idea. I, too, want to avoid "leaving" selection after first changed placed. Actually, this is how it is coded right now. But, it's not like the selection is "left" there. It is set there. So, right now, when you, say, right-click on word with typo and use browser spellchecker, the DOM Selection is set on the changed word. Then, if we don't mess up with it in I think that if we use mutation, it's perfect if we let the browser set the selection because we are using native browser algorithms. The thing is that we should not mess up the selection set by the browser. In order to do so, without changing So yeah, the idea is to set the selection, but basing on actual DOM selection.
I also thought about changing how input works. I don't like that you make multiple one-letter changes. This also casued a bug that I already kinda reported here: https://github.com/ckeditor/ckeditor5-typing/issues/39#issuecomment-250725261. I don't see a reason not to replace the whole text instead of diffing. Still, in this scenario, we need to use DOM selection to properly set view selection. |
Yep... Unless we'll have some brilliant idea. E.g. the one I can think of (which is not necessarily brilliant) is converting a piece (current block or sth) of the DOM to a temporary view structure in which we'll calculate the correct position of the view selection, and then, translate it somehow to the document view. |
Of course, that's what I am talking about when I say that we need DOM Selection :). |
Okay so after F2F discussion here is what we are agreed on:
We decided that we will fix what is to be fixed directly in This issue will be left opened in case we want to implement general solution in |
I proposed some changes in ckeditor/ckeditor5-engine#626. |
Fixed by ckeditor/ckeditor5-engine#626. |
This one is tricky.
View and view events should build an abstraction laver over the DOM. In case of the mutation it means that old and new children are view nodes as well selection should be a view selection.
The problem is that new nodes are not yet in the view tree, they are only listed as new children of the parent element which is in the view tree. But that parent element does not have new children in the list of the child node (the change have to go to the model and back to be applied on the view document).
Now the selection. It usually land in that new node. It means that it need to convert DOM selection positions to the positions in the node which have no corresponding view elements in the view tree. It means that we can not use standard
DomConverter
method which assume that DOM and View are similar, or return null if it is not possible to return corresponding position. We need to find the way to put the position in the new view element which are only on the list of the mutations.Fortunately we should not use this position very often. In most cases model will know better where to put selection after changes. On the other hand this information might be useful for instance for the typing: we may want to put the caret after inserted text on typing, but have selected word in case of autocorrection. Or if the autocorrection changed only one letter in the word the whole word should be selected or the caret should be after that word. To some extent, we are able to guess where the selection should be put based on the change which is done, but without the information where the native selection was we may have some issues.
The text was updated successfully, but these errors were encountered: