Fix the scrolling issues, take 4

This reapplies 2369dd5db6bfc895d7b1240e3b31d46a1699a887 "Handle jump to line as
in xterm" and a6c4eb0a64d5ae445ca74abb4290394dbfb676e0 "Fix another
jump-out-of-the-scroll-region bug".

We need these after all. I've thought 8ed9aa32 would fix everything without
these but I can still find cases where it doesn't work (scrolling vim in tmux).
Not only that but these patches had a silly bug in them and now that is fixed as
well.

Also, switch to an opt build.