getSelectedText computes startIdx, endIdx, and annotated substring