Introduce Range#hasContent to check if there is any content in a Range #4168
Labels
package:engine
status:discussion
type:feature
This issue reports a feature request (an idea for a new functionality or a missing option).
Milestone
From time to time we have a feature, in which we have to do something if given range has (or does not have) content.
This is tricky.
What is "content"? When do we want to check "content"? When a user perceive that something has or does not have "content"?
For me, the content is anything that holds some data. Grouping elements, styling elements, ui elements, these are not content. Text and data elements like images are content. These are represented by text nodes and empty elements.
Now the tricky question is whether for example list item or (empty) block quote holds any meaningful data. Though we could argue, I think we can assume that they are not, to simplify the concept.
If you agree that data is
Text
andEmptyElement
it is clear that "not-having-content" is something else than "start position touching end position". Position touching is something else and is used for comparing whether two position are very similar.Therefore I am for introducing
Range#hasContent
method, that would traverse through the range (usingTreeWalker
) and check if the range has any content. I propose this name because it is more meaningful thanisEmpty
, which could be mistaken withisCollapsed
.Now, it is a bit easier to implement this in
view
than inmodel
. inview
we have elements that already has some meaning, likeAttributeElement
,ContainerElement
,UIElement
andEmptyElement
. In model, though, we have onlyElement
andText
. So it is not possible to tell something that is converted to emptyContainerElement
from something that is converted toEmptyElement
.In
view
the function would check if there is anyText
orEmptyElement
in the range. Formodel
, we need to enhance the tree to implement this function.The text was updated successfully, but these errors were encountered: