added text range check for anchor and activeIndex