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
Split Selection into (Static)Selection and LiveSelection #3644
Comments
https://github.com/ckeditor/ckeditor5-engine/issues/441 prove that we need static selection. |
My question is whether we really need a const selection = {
ranges: Array.from( this.editor.document.selection.getRanges() ),
isBackward: this.editor.document.selection.isBackward
};
this._items.push( { batch, selection } ); |
It is not very object oriented ;) I think that some methods might be useful. Also we may want to pass this object somewhere, for instance set model selection to the values from the static selection. |
You could retrive this kind of object by using, let's say |
I am not saying t hat |
https://github.com/ckeditor/ckeditor5-engine/issues/441 also do not need attributes. I agree that |
I presume that we need attributes to represent empty inline styles. And we definitely need other selection methods. Selection is a real thing and has a behaviour (== methods), state and all things which make it a clear nominee for a class (== an object with properties and with methods to work with that object). Plus, we may have multiple selections – one real, many collaborators' selections, selections in the undo, selections used temporarily in your code to represent some selection state (like arguments for |
This feature is needed in 0.1.0 because right now undoing deleting gives you a non-collapsed selection. That happens because right before delete happens the selection is extended to the left/right to contain the content that delete should remove. If we had static selection we could use it to tell |
My question was whether we need attributes API in |
I think we can add attribute support at any moment. We should add it as soon as we found usage for it. |
|
Changed |
The request comes from the question "what are we going to pass to methods like
deleteContents()
?". In CKEditor 4 we usually had a command that automatically works on the real selection and helper methods which accept ranges. The command of course call one of the helper methods, so they exist mostly for code reusability reasons. Other algorithms can use those in order to build some more complex behaviours.In CKEditor 5 the 4's scheme with util methods working on ranges does not fully make sense, because:
In other words, it's clearly visible that algorithms need to work on selection. Theoretically we could now do this:
However, the current implementation of the
Selection
operates on live ranges, what mean that the selection needs to be detached once not needed. Otherwise, the editor will quickly become sluggish due to huge number of attached live positions.Therefore, let's split the selection into two classes. Basic, static selection that can be used as a feed for utils, and live selection for the document's main selection (and those who know what they are doing).
The split should be pretty simple to do as live ranges are created in just one place.
PS. For now we can freely live without the static selection. Simply, in the tests (which, for a time being, will be the only code that uses the feature utils) we can use live selection and detach it when needed.
The text was updated successfully, but these errors were encountered: