ivirabyan / jquery-mentions

Adds mentioning support to your text fields.
http://ivirabyan.github.io/jquery-mentions/
MIT License
114 stars 49 forks source link

Bugfix: deleting mentions, when they are more than one, lead to inconsistencies #44

Closed micobg closed 8 years ago

micobg commented 8 years ago

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.

ivirabyan commented 8 years ago

Good point, thanks!