Keep correct cursor pos when resizing. Fixes #2018.

Also fixes #2017.