fix ensureVisible logic