SimpleMobileTools / Simple-Notes

A simple textfield for adding quick notes without ads.
https://www.simplemobiletools.com
GNU General Public License v3.0
825 stars 271 forks source link

Fixed slow search for larger files #701

Closed ram-on closed 9 months ago

ram-on commented 9 months ago

Issue

Searching for text using a text file that holds few kilobytes of data results in the app become unresponsive, extremely sluggish and very slow.

Cause

The issue is cause by the EditText.highlightText(). Whenever a user tries to search for a string, this function tries to finds all instances of the string and replace them with SpannableString. More specifically, EditText.setText() function is extremely slow when setting SpannableText: this function is called for every search instance found.

Solution

Instead of highlighting all search instances, the code now just highlights the first result and once the next button is clicked it will highlight the next result and so on.

Additionally EditText.setText() function appears to be faster then BackgroundColorSpan is used instead of SpannableText.