fix exception when in preview while no caret is in the view
fix exception when in preview while no caret is in the view