Keep current scroll position when zooming the document

This PR is an attempt to rewrite #3446 from the ground up, to hopefully be able to pinpoint and fix the bugs in that implementation.

Fixes #1521 and replaces #3446.

/cc @brendandahl