private void RefreshHighlight() { List <Run> runs = new List <Run>(); if (DisplayString != null && HighlightString != null) { string displayStringLower = DisplayString.ToLower(); string highlightStringLower = HighlightString.ToLower().Trim(); int highlightStartIndex = displayStringLower.IndexOf(highlightStringLower); if (highlightStartIndex > 0) { runs.Add(GenerateRun(DisplayString.Substring(0, highlightStartIndex))); runs.Add(GenerateRun(DisplayString.Substring(highlightStartIndex, highlightStringLower.Length), true)); if (highlightStartIndex + highlightStringLower.Length <= DisplayString.Length) { runs.Add(GenerateRun(DisplayString.Substring(highlightStartIndex + highlightStringLower.Length, DisplayString.Length - highlightStartIndex - highlightStringLower.Length))); } } else if (highlightStartIndex == 0) { runs.Add(GenerateRun(DisplayString.Substring(0, highlightStringLower.Length), true)); if (highlightStringLower.Length + highlightStartIndex < displayStringLower.Length) { runs.Add(GenerateRun(DisplayString.Substring(highlightStringLower.Length, DisplayString.Length - highlightStringLower.Length))); } } } runsToRender = runs; }
private int FindPrecedingWordEnd() { if (_cursorIndex == 0) { return(_cursorIndex); } var isOnWhitespace = char.IsWhiteSpace(DisplayString[_cursorIndex - 1]); return(DisplayString.Substring(0, _cursorIndex).ToList() .FindLastIndex(a => char.IsWhiteSpace(a) != isOnWhitespace) + 1); }
public void AddString(string text) { if (_selectionActive) { DeleteSelected(); } DisplayString = DisplayString.Insert(_cursorIndex, text); DisplayString = DisplayString.Substring(0, Math.Min(2500, DisplayString.Length)); _cursorIndex += text.Length; ClampCursor(); }
private int FindFollowingWordEnd() { if (_cursorIndex == DisplayString.Length) { return(_cursorIndex); } var isOnWhitespace = char.IsWhiteSpace(DisplayString[_cursorIndex]); var foundIndex = DisplayString.Substring(_cursorIndex).ToList() .FindIndex(a => char.IsWhiteSpace(a) != isOnWhitespace); if (foundIndex == -1) { return(DisplayString.Length); } return(_cursorIndex + foundIndex); }