save and restore a cursor position or selection