public void TryCloseTag(ITextChange textChange, IList <TextManipulation> manipulations) { var currentTag = _state.ParseCurrentTagName(); if (textChange.NewText == "/" && !string.IsNullOrEmpty(currentTag) && currentTag != "/") { var text = _text.Span; int pos = _state.ParserPos; char c = ' '; while (char.IsWhiteSpace(c) && text.Length > pos + 1) { pos++; c = text[pos]; } bool tagAlreadyClosed = c == '>'; if (!tagAlreadyClosed) { manipulations.Add(TextManipulation.Insert(_position + 1, $">")); } else { var closingTagPos = FindClosingTag(currentTag, pos + 1); if (closingTagPos != null) { manipulations.Add(TextManipulation.Insert(_position + 1, $">")); manipulations.Add(TextManipulation.Delete(_position + 1, closingTagPos.Value - _position)); } } } }
public static IEnumerable <TextManipulation> AsManipulations(this ITextChange textChange, int offset = 0) { if (!string.IsNullOrEmpty(textChange.OldText)) { yield return(TextManipulation.Delete(textChange.OldPosition + offset + 1, textChange.OldText.Length)); } if (!string.IsNullOrEmpty(textChange.NewText)) { yield return(TextManipulation.Insert(textChange.NewPosition + offset + 1, textChange.NewText)); } }