[TextEditor] Don't modify list in foreach