BF: fix calculation of trailing span and visualIndexAt