Handle folding and range highlighting using event listeners