SearchQuery is applied, is it possible to get the number of total hits inside the document?
No, in order to avoid doing lots of work on big documents, the search extension doesn’t eagerly count matches.
Seeing the number of search results and the current result index is very useful and common, I would really love to see this count in CodeMirror too.
- Make this a config option of the search component
- Make search as smart as possible: stop searching at 1000 results and show “999+” results. Or be lazy and stop searching after x lines, show a button “calculate result count” in that case to force the user to click the button to actually find the count if they are interested. Or only find all results when the document size is below a certain maximum, optionally showing a button to calculate the total results anyway.
- Just challenging your assumption: how bad is the search performance really on “big” documents? Maybe it’s just acceptable if search works “a bit slow” on a large document?
I spent some time playing with this, and decided against including it in the search package, since it introduces a bunch of new complexity and performance cliffs that I’m not comfortable with.
On the upside, it should be possible to track matches in a custom extension, and report them in a custom search dialog, if you really need this.