mathquill/mathquill — pull request #246 by laughinghan (2014-02-24 08:37:15+00:00)
Title: Adjacent SupSub's always merged into one command #big

Just a subscript or superscript by itself is still a SupSub with only 1 block, but adjacent ones (like `_a^b`) are now combined into a SupSub with 2 blocks, with CSS similar to Fraction's to stack one above the other, rather than 2 adjacent SupSub commands stacked with negative margins making them overlap calculated "manually" in JS by `SupSub::edited()` (formerly `redraw()`).

Further, typing `_` or `^` adjacent to an existing SupSub will not insert a new SupSub, but rather insert the cursor into that side of the SupSub.

How:

When you first type (or render from LaTeX) `_` or `^`, they are momentarily always a SupSub with only 1 block, either only a subscript or only a superscript. Then, right after `.postOrder('finalizeTree')`, `finalizeInsert` now does `.postOrder('contactWeld')` so that adjacent "weldable" nodes can "contact weld" together, i.e. if there is a subscript adjacent to a superscript, one is removed and the other becomes a SupSub with 2 blocks; and if there are any two adjacent subscripts or superscripts, they're combined into a single subscript or superscript whose contents is the concatenation of the originals.

(Note:

- "Contact welding" is also something I had wanted to do with TextBlock's and had been implemented super hackily before, but it looks like I gave up on that?
- `.postOrder('finalizeTree')` needs to happen first because `SupSub::contactWeld` relies on the `.sub` and `.sup` of the rightward SupSub having been initialized by `.finalizeTree()`.
- This has to be done in `finalizeTree` for it to work when writing `_` or `^` with `.writeLatex()` (exposed by the public API method `EditableField::write()`) adjacent to an existing SupSub, it can't be done in `createLeftOf` and `parser`, because `createLeftOf` isn't called and `parser` is called too early, before the SupSub can know about SupSub's it's being written next to.

)

Move `insLeftOfMeUnlessAtEnd` out of the private `SupSub` closure, for use by its descendants (subscript and superscript), but unchanged.

Move `prayWellFormed` out of the private `Fragment` closure, for use in tests.

`SupSub::latex()` now requires `SupSub::finalizeTree` called first (to set up `.sub` and `.sup`), so `latex.test.js` has to `.postOrder('finalizeTree')`.