set a couple of more options for the preview window
be sure to not keep the cursor in the preview window
before opening preview window, check that there exists actually a diff
when there are no changes and the preview window is open, close it