This looks to be exactly the same kind of thing that
emacs calls "selective display." In that editor mode, you can hide any image that is indented more than N spaces. Groups of one or more hidden lines appear in the editor as a ... mark appended to the previous visible line. Your cursor moves right over the elipses, you can select everything including an elipses, you can delete or copy chunks that include elipses, etc.
The principle can be extended to any sort of do-or-don't-show filter, of course.
- You will need to read through the whole file once.
- You will need to index line positions, either indexing all lines, or filtered lines.
- If you're threaded, you can index in a separate thread.
Fill the display once the indexer has indexed enough to fill the first page, but you may need the display to "wait" for the indexer sometimes if you let the user move around before the indexer has finished.
- You can save the index to a file if the filtration is too slow to perform often.
- You can "index the index" for intensely huge sources, where even the index would outstrip memory available.
- When the user wants to scroll into areas not on the screen, use your index to re-read the applicable portions.
- When the user wants to see things that are hidden, use your index to re-read the applicable portions.
Think of your index as being a hash of weak references to strings, if you know what that means. If the memory is tight, don't keep the strings around, but if they're needed again, then don't hesitate to reconstruct them.
--
[ e d @ h a l l e y . c c ]