You can reproduce the bug when you delete two or more mentions simultaneously or by deleting all text (with more than one mention).
The problem comes from the loop over the @mentions array that removes the unnecessary mentions. Compiled version of the loop iterates over the copy of @mentions. When we remove the mentions with index 0, the second iteration tries to remove mention with index 1, but this mention is already at he position 0 in @mentions array. As a consequence, this mentions will never be removed but instead someone else may be deleted.
This problem can easily be circumvented by crawl array backwards.
You can reproduce the bug when you delete two or more mentions simultaneously or by deleting all text (with more than one mention). The problem comes from the loop over the
@mentions
array that removes the unnecessary mentions. Compiled version of the loop iterates over the copy of@mentions
. When we remove the mentions with index 0, the second iteration tries to remove mention with index 1, but this mention is already at he position 0 in@mentions
array. As a consequence, this mentions will never be removed but instead someone else may be deleted. This problem can easily be circumvented by crawl array backwards.