fix incorrect target element calculation for text editors