/// <summary> /// Return a StyledParagraph reflecting the insertion of a single character /// into the text. This method will attempt to reuse the given paragraph, /// but may create a new paragraph. </summary> /// <param name="aci"> an iterator over the text. The text should be the same as the /// text used to create (or most recently update) oldParagraph, with /// the exception of deleting a single character at deletePos. </param> /// <param name="chars"> the characters in aci </param> /// <param name="deletePos"> the index where a character was removed </param> /// <param name="oldParagraph"> a StyledParagraph for the text in aci before the /// insertion </param> public static StyledParagraph DeleteChar(AttributedCharacterIterator aci, char[] chars, int deletePos, StyledParagraph oldParagraph) { // We will reuse oldParagraph unless there was a length-1 run // at deletePos. We could do more work and check the individual // Font and Decoration runs, but we don't right now... deletePos -= aci.BeginIndex; if (oldParagraph.Decorations == null && oldParagraph.Fonts == null) { oldParagraph.Length -= 1; return(oldParagraph); } if (oldParagraph.GetRunLimit(deletePos) == deletePos + 1) { if (deletePos == 0 || oldParagraph.GetRunLimit(deletePos - 1) == deletePos) { return(new StyledParagraph(aci, chars)); } } oldParagraph.Length -= 1; if (oldParagraph.Decorations != null) { DeleteFrom(deletePos, oldParagraph.DecorationStarts, oldParagraph.Decorations.Count); } if (oldParagraph.Fonts != null) { DeleteFrom(deletePos, oldParagraph.FontStarts, oldParagraph.Fonts.Count); } return(oldParagraph); }