marijnh/CodeMirror2 — pull request #203 by soniciq (2011-10-09 22:59:56+00:00)
Title: Added coordsFromIndex method along with tests and updated manual

As mentioned in https://github.com/marijnh/CodeMirror2/issues/201#issuecomment-2341615, here is the pull request. For reference, I've copied the comment here:

> Hi Marijn,
>
> I discovered a nice way of doing this so I will be making a pull request shortly to include a "coordsFromIndex" method.
>
> The method I'm using is pretty fast as it doesn't do any string matching. The function basically loops through the strings in the lines array until the total of their lengths so far exceeds the index we are interested in, then it can easily calculate a {line, ch} object. The 'line' comes from which line it's got to in the loop and 'ch' is calculated by subtracting the total chars in previous lines from the index we want. The function also takes into account '\r\n' in IE although I personally think it would be best to stick to "\n" at all times.
>
> I have added the method, written some tests for it and updated manual.html with the new method. Pull request on it's way.
>
> Thanks for your pointers on this.