Improve cursor upstream/downstream logic
Improve cursor upstream/downstream logic

This makes the logic hopefully easier to follow, and also makes it
more robust to measurement changes. It should also make rendering
handle the upstream case correctly.

google/xi-editor,fuchsia-mirror/third_party-xi-editor,google/xi-editor,fuchsia-mirror/third_party-xi-editor,fuchsia-mirror/third_party-xi-editor,google/xi-editor,fuchsia-mirror/third_party-xi-editor,google/xi-editor,modelorganism/xi-editor,modelorganism/xi-editor,modelorganism/xi-editor