[SuperEditor] Fix crash with selection across nodes when using the tags plugin (Resolves #2479) #2480
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.
[SuperEditor] Fix crash with selection across nodes when using the tags plugin. Resolves #2479
To reproduce the issue:
Select a paragraph node completely (all text) and then continue the selection to another paragraph node above it. Or simply select multiple nodes partially.
Exception:
The issue is that we are trying to use the caret position to extract the text. However, when multiple paragraphs are selected, we are always trying to extract the text using the end position of the selection, which will be invalid when one paragraph is larger then another.
We discussed about modifying the tag find logic for the action tags to only care about collapsed selections, because an action tag only makes sense while the user is typing, and when the user is typing, the selection is always collapsed.
There are some tests that ensure we extract tags with expanded selections, so I had to modify those tests to ensure the opposite.
Also, I suggest we change the composing reaction to only start composing if the user is actually typing. Currently, if a text contains a substring that is matched as a tag, for example "/hello", just by placing the caret somewhere in the middle of "hello" the reaction already starts a tag composition. We have a ticket for that: #2392.