marijnh/CodeMirror2 — pull request #439 by njx (2012-03-13 00:25:52+00:00)
Title: Fix bookmark bug when splitting lines

I ran into a bug where hitting return in the middle of a line would sometimes invalidate bookmarks that are after the location of the inserted newline, and tracked it down to a bug in Line.split().

When the user hits return in the middle of a line, CodeMirror first splits the line. As part of this, it takes any marks that are past the split point and attaches them to the new second line, but doesn't remove those marks from the original line's mark list. Then, when calling replaceText(), it runs through the list of marks on the old line and tries to update them--erroneously including marks that are now attached to the new (post-split) line. If some of those marks have offsets (relative to the new line) that are larger than the new length of the old line, CodeMirror thinks those marks are dead.

(The existing unit tests didn't catch this because in the ones that split the line, the split point was close enough to the location of the bookmark that the new bookmark's character offset after the split was small, so was still within the shortened range now covered by the original line.)

This pull request fixes the problem by removing the mark from the original line after attaching it to the new line. It also adds a unit test for the specific case mentioned above. The other marker and bookmark unit tests still pass after this change.