Introduce a way to know whether the selection is in the editor #6485
Labels
package:engine
type:feature
This issue reports a feature request (an idea for a new functionality or a missing option).
Milestone
📝 Provide a description of the new feature
There is a difference between an editor being not focused and editor not having a selection inside it. In general, when the editor does not have selection inside it, it is not focused. However, sometimes editor is not focused but still has selection. For example, when you switch a browser tab.
A case for this is an issue that was reported to us by real-time collaboration users. When there are multiple editors on one website, there is a user selection in each of them. This is confusing and doesn't tell where exactly the user is editing.
Unfortunately, using just focus is not the best solution - as I pointed out - for example - the focus is lost when you change browser tab.
Instead, I propose a new flag, which would inform whether the DOM selection is in a given editor. It would be complementary to
view.Document#isFocused
. It would be set bySelectionObserver
which already does some processing of selection change event.Now, the problem is where we want to add this flag. I see four candidates:
view.View#hasDomSelection
-View
class already has some stuff connected to DOM, for example#domRoots
andDomConverter
instance. It also keepsRenderer
instance (although it is not public). It is easily reachable. It also creates observers, so it makes sense thatSelectionObserver
would work on it.view.DocumentSelection#isInDom
- I propose this because selection is another place where I'd look for a flag like this. I am not sure, however, if parts of the view should keep such information. I am not sure if this is something that selection should know about. I think it should work in the view scope and care just about view things and other, higher-level parts of code should use it and convert it.view.Document#hasDomSelection
- I propose it mostly because it already has#isFocused
. Honestly, I don't see a reason whether this flag should be here, for the same reasoning as for the selection object.Editor#hasDomSelection
- maybe it would be a good place but is hard to reach from the bottom. Plugins have access to the editor butSelectionObserver
does not.The text was updated successfully, but these errors were encountered: