Fix whole word search slowdown in editor
Reduce repeated iteration through the full text
when counting the number of occurrences of whole
words while searching a file in the editor.
(cherry picked from commit 2433287871ec5ccdf1f85e3e9c057a1a589d3848)