Rework QPlainEditSearchWidget
Work in progress. This should address some performance issues and some minor issues in QPlainEditSearchWidget.
- runs search across the entire document only when required (when the search term is changed and when the QPlainTextEdit is modified and the search is invalidated); otherwise, for the up/down search and replacements, it uses the QTextCursor list fetched in the first search.
Missing / required changes:
- further testing
- could be simplified
- benchmark to compare with previous version
- further improvements by replacing deboucing with asynchronous search
FWIW, this isn't going to make the search very fast. I tried this change and a few other things and ran some benchmarks and it seems the biggest slow down is setExtraSelections. As long as we are using that, things will be slow. You can't do this async. Profile below shows the amount of time doing the search (far right) vs the amount of time showing the results.

So besides the bug fixes etc, imo the added complexity is worth it. To make the search fast we need to avoid setExtraSelections and do the search highlighting outselves for only the region that is visible to the user for a start. To be clear by fast I mean ~100ms max for files around ~5MB on a cpu from 2015 or so.
Good news is that the search highlighting code is already there in QtCreator's code. One just needs to to adapt it to our text editor.
We can also use our syntax highlighter to highlight search results
Thanks for the suggestions @Waqar144 . Will get back to this as soon as I get some spare time.