Fix bugs when switch between document and image previews.