Reintroduce non leaf inline and block accessors to value #2937
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Is this adding or improving a feature or fixing a bug?
Improving and adding.
What's the new behavior?
This reverts
value.inlines
andvalue.blocks
to not filtering for only leaf nodes and adds specificvalue.leafInlines
andvalue.leafBlocks
.The new behavior is that
value.inlines
andvalue.blocks
return all respective nodes of those types andvalue.leafInlines
andvalue.leafBlocks
have been added to access leaf nodes specifically.How does this change work?
This issue has a few different levels and I think this change is the most straight-forward way to resolve them. The main issue is that currently if the selection is in a node that is not a leaf of its type in the document tree, but the selection does not include the actual leaf nodes,
value.inlines
or '.blocks' will be completely empty even though the selection contains nodes of those types.This is due to this line here where we check whether the node is a leaf node, but don't give the context of the desired range. Thus the described behavior of "bottom-most {nodes of type} in a range" is not really accurate, as it will only return inlines if they are leaf nodes in the context of the document tree as a whole, not just for the selection.
An alternate approach to make this behavior less confusing would be to pass the context of the range to the check for whether the node is a leaf node or not, but I think this raises some questions about the nature of leaf nodes and whether the context of a range should affect whether a node is considered a leaf node or not. Can a node be a leaf for just a current range? To me that seems kind of unintuitive. For example, if
getLeafInlinesAtRange
performed as it's described and returned the "bottom-most" nodes in the range then we could likely be returning "leaf" nodes that have children of their same object type in the document tree as a whole which seems very unintuitive.Thus I think the solution that makes the most sense is to keep the functionality for
getLeafInlinesAtRange
as it is but not use it to source inlines forvalue.inlines
, and instead add a separate propertyleafInlines
to the value model. I think this should resolve confusion going forward.On a higher level design note I also think it just plain doesn't make sense to have
value.inlines
andvalue.blocks
make non-explicit assumptions about what sort of nodes are desired. Even without adding.leafInlines
or.leafBlocks
if the user wants only leaf or root nodes of those types than they can filter them as they wish! It is unintuitive to have a generic.inlines
property and then only have it return a subset of the inlines.Have you checked that...?
yarn test
.yarn lint
. (Fix errors withyarn prettier
.)yarn watch
.)Does this fix any issues or need any specific reviewers?
🤷♂