private string GrabNeededCharsAsHighlight(TextRun template, string text, int offset) { int grabChars = Math.Min(_charsToGrab, text.Length); HighlightedTextRun htr = MakeHighlightedText(template, text.Substring(0, grabChars), offset); _si.Content.Add(htr); _charsToGrab -= grabChars; text = text.Substring(grabChars); if (!string.IsNullOrEmpty(text)) { TextRun tr = template.Clone(); tr.Content = text; _si.Content.Add(tr); } return text; }
private void AddTargetObject(TextRun textRun) { string text = textRun.Content; if (_location.CharOffset > 0) { TextRun tr = textRun.Clone() ; tr.Content = text.Substring(0, _location.CharOffset); _si.Content.Add(tr); text = text.Substring(_location.CharOffset); } _charsToGrab = _location.Length; text = GrabNeededCharsAsHighlight(textRun, text, _location.CharOffset); }