Fix bug in lineIsHidden test

It would occasionally mark lines as hidden that were needed to display
parts of other lines.

Issue #1161
Update maxLine when adding or clearing a collapsed range

Closes #1161