Implement the algorithm for positoning cues when the snapToLines flag is set.

Builds on pull request #239.

Partial fix for #112.