Backport features and fixes from ST3

-Preserve selections and viewport when performing saveas function
-Ensure file is focused when file is open