klaussilveira/gitlist — pull request #421 by khornberg (2014-02-25 01:55:21+00:00)
Title: Add context and highlighting to a search

This PR works but I could use some help making it better and I'd like to know if this is a desired feature.

![gitlist highlighted search](https://f.cloud.github.com/assets/3442051/2253467/4adc901a-9dbf-11e3-9f5a-adb855a2cb45.png)

Highlighting is done with CodeMirror overlays. I had to upgrade to CodeMirror version 3 (I used 3.21) to use them. The downside to upgrading is that line numbers can only be simple text. CodeMirror now casts all input to the `lineNumberFormatter` function as a string so html is not displayed correctly (see Code Mirror issue #1456).

Help needed
1. Optimization of the searchTree function.
2. Intelligent line numbers on the search page. Currently they link to nothing. Ideally they would link to the file and line number.
3. Large file suppression can be better. Currently only suppresses lines greater than a 1000 characters. The intent was to suppress minified files.
4. Application of the Code Mirror overlay could be optimized.

5. Finally, I'm not sure if this can be fixed. Code Mirror refreshes each editor on the window resize event. This means that if a user resizes the window after searching for a term, the line number links are overwritten by the refresh (back to plain text). This doesn't matter if the decision is to have the line numbers not link to anything. If the line numbers need to link to something then I'm not sure how to solve this problem. In the Code Mirror source, line #1620 has the definition of what is happening.