Stop reusing currentFold variable in closestCommonParent calculation.

We were doing this when closing a fold, and it resulted in
poor setting of lastFold, which then threw off our decisions
on how to continue closing the fold and where to mark fold
starts.
Switch to WWDC sample code for ViGlyphGenerator.

We’d done some small updates to it, but there were some
weird memory free corruption issues here and there, so we
just copy-paste the original WWDC code directly.
Switch totalOpenedRange in fold opening to an NSValue.

This deals with an issue with using __block with NSRanges.
Don't try to open a fold if it's already open.
Fix off-by-one issue in deciding whether to open the current fold.
Stop reusing currentFold for common parent in fold opening.
Show closed fold attachment in first attribute of nested closed folds.

This when opening a fold that has nested closed folds inside
it.