fix(placeholders): fix placeholders not being selectable #1045
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.
Overview
After the improvements to the gapcursor/position resolution from mouseclicks, placeholder nodes
threw erros when clicked on. This was because the position resolution logic tries to
find a position with a parent that is the same parent that the text cursor would have if
it would be standing where you clicked. It does this by walking upwards and comparing the value
of parent with the value of the node at the "inside" position (which prosemirror already calculates).
However, in the case of atom nodes, the first position checked already starts with a parent that
is the parent of the atom, meaning the walk upwards will never result in the correct position.
Additionally, the loop was missing a bounds check for depth=0, which caused the error
connected issues and PRs:
Setup
best way to test is npm link in the plugin repo, and try out the article structures and their
placeholders
How to test/reproduce
Challenges/uncertainties
Switching on the node being an atom is an educated and afaict a relatively conservative bet.
There might be more scenarios where the walk upwards will not find the right position.
Additionally this may result in some more scenarios where a good gapcursor can not be found,
since I don't have a reproduction of the cases the original code was trying to solve.
Checks PR readiness