Fix various sticky/broken cursor issues.

This still isn't quite right, but it's a lot less broken than before, at least.