Perhaps I should change the variable name. pageCoords.bottom is the bottom of the cursor relative to the scroller element on the page. pageCoords.top is the top of the cursor. In other words, there's only a few px difference between the two. I could average them together, but it makes little difference in the visible scrolling.

Perhaps I also need a better comment there to explain the calculation. It checks to see if the cursor position is less than the size of the scroller on the page * CENTERING_MARGIN (in this case 10%) + the padding adjustment to actually make it 10%, or if the cursor position is in the bottom 10% of the scroller (again with the padding adjustment).

Does that make sense? I believe the logic is right (and if you try it out, it works nicely in my experience), but I should rename most of those variables to make everything much more self-explanatory, rather than using codemirror lingo.