Remember viewport position and selection on save

Added code which should restore the viewport scroll position and the selection after save, instead of scrolling to the top.