Components: Refactor insertIndex from Inserter component #4551
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.
This pull request seeks to refactor the
Inserter
component to separate handling of insertion point and visibility. Previously the Inserter component was responsible for: setting the insertion point, showing the insertion point, and inserting a block at the current insertion point. To achieve this, it received two propsinsertIndex
andinsertionPoint
which often -- but not always -- held the same value.The changes here distinguish setting an insertion point to be the responsibility of where it is relevant; namely, the sibling inserter component.
showInsertionPoint( index )
andhideInsertionPoint()
have been replaced withtoggleInsertionPointVisible( isVisible )
andsetInsertionPointIndex( index )
.A hope here is to try to clarify a difference between an explicit insertion point (reflected in
state.blockInsertionPoint
) and the implicit insertion point (the logic contained within thegetBlockInsertionPoint
selector, inserting after content or the current block selection).The main downside is that since there are now two separate actions for setting the insertion point index and its visibility, there may be separate renders which occur. This can be seen when, while a block is selected, you use the header inserter and then cancel both insertion and block selection by clicking on the editor background. The insertion point shows briefly at the bottom of the post content.
Testing instructions:
Verify that there are no regressions in the behavior of the insertion point, notably around selection (including multi-selection), sibling block insertion, and the header inserter (with and without selected block, in Visual and Text modes).
Ensure that unit tests pass: