-
-
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
Link balloon does not update its position on external changes #4788
Comments
I suppose it may be a very tricky problem. The first problem is that the balloon must be re-positioned to something on each render, which is the selection (and the The second problem is what to do when the range the balloon was attached to does not make a sense anymore. Like when the external change deletes the paragraphs. Should we simply close the balloon then? Because if yes, then it will mean the user loses their content, which may not be a very good UX. I see no other solution, though 🤔 |
I don't see a problem here. We have two separate mechanisms here:
These two mechanisms should be implemented independently. It makes it easier to think about the implementation and behaviour (at least for me). The first point – events on which the balloon should be opened or closed:
These are the actions (I might've forgotten some). Note that all of them are intentional – they are user actions, not background actions. This ensures that the user will not be surprised with disappearing balloon (or that it will happen as infrequently as possible – see the next paragraph). Now, in between these two actions, we need to constantly reposition the balloon. We need to do that on environment changes (when content doesn't change) like scrolling and on content changes (collaboration). To what target rect we should be positioning? I can see that initially the balloon is positioned to the link element itself. This is fine. This can be maintained as long as long as a link element can be found in the current selection. Keep in mind that the user's selection is never lost – engine's model and view will maintain the selection infinitely – even, despite any possible collab changes. The only thing you don't know is where this selection will end. Due to collab changes the originally selected content can be removed (so selection gets collapsed) or a link in which the selection was might be removed or split. All this may happen. The link should, IMO gracefully handle these changes. So:
tl;dr – implement each mechanism separately, handle changes gracefully, keep the least state possible (e.g. don't try to memorise the original link element – it may change!). |
Let's hope I didn't miss something ;) |
What if this is a new link scenario? There's no link in the model/view then. |
I see 2 major scenarios here:
|
So, initially you was positioning to the caret, right? Upon some collab changes, the caret will be moved around the content. In 99.9% scenarios – it will end up in some other place where the link can be created – no problem there. So just let's reposition to that caret and that's it. If the caret ended up in a place where link can't be created... this may happen if there were some serious changes done. This is the edge case where closing the balloon would be reasonable. |
Fix: Link balloon should update its position upon external document changes. Closes #113.
It doesn't work only for the balloon of the new link. It works fine with balloon attached to existing link element.
A follow-up of https://github.com/ckeditor/ckeditor5-ui/issues/198.
The text was updated successfully, but these errors were encountered: