fix: Support inline nodes with content in @tiptap/suggestion #2648
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.
Problem: @tiptap/suggestion's
findSuggestionMatch
only works when inline nodes are leaves. When you have an inline node with content, in our case a footnote modeled off of https://prosemirror.net/examples/footnote/, suggestions after that node are broken.This happens because the current logic relies on
textBetween
returning a string whose length exactly matches the absolute position range of the node. This is true with text nodes, as well as leaf nodes like a mention, but not a content node like footnote because its opening/close take up position spaces.Solution: I don't think textBetween on the entire parent node is actually needed here. Just looking at the text node immediately before the suggestion fixes the problem and seems simpler as well.