Skip to content

Commit

Permalink
Hugely improve performance of finding text in editor window. (#4886)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrant authored Aug 21, 2024
1 parent d59740f commit 279c224
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.view.View
import org.wikipedia.edit.richtext.SyntaxHighlighter
import org.wikipedia.util.DeviceUtil
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.StringUtil
import org.wikipedia.views.FindInPageActionProvider
import org.wikipedia.views.FindInPageActionProvider.FindInPageListener

Expand Down Expand Up @@ -62,10 +61,16 @@ class FindInEditorActionProvider(private val scrollView: View,
searchQuery = text?.ifEmpty { null }
currentResultIndex = 0
resultPositions.clear()

searchQuery?.let { query ->
resultPositions += query.toRegex(StringUtil.SEARCH_REGEX_OPTIONS).findAll(textView.text)
.map { it.range.first }
val textToSearch = textView.text
var index = 0
while (index >= 0 && index < textToSearch.length) {
index = textToSearch.indexOf(query, index, ignoreCase = true)
if (index >= 0) {
resultPositions.add(index)
index += query.length
}
}
}
scrollToCurrentResult()
}
Expand Down

0 comments on commit 279c224

Please sign in to comment.