// <summary> // Checks if the this array has all elements in the same order as in value array in the start of the this array. // </summary> public static bool ContainsInStart(this Match[] container, Match[] value) { if (container == null || value == null) { return(false); } if (container.Length == 0 || value.Length == 0) { return(false); } if (container.Length < value.Length) { return(false); } for (int i = 0; i < value.Length; i++) { if (!MatchesComparer.Equals(container[i], value[i])) { return(false); } } return(true); }
private async void OnTextChanged(object sender, TextChangedEventArgs e) { if (TextChanged || PatternChanged) { _previousText = Text; _previousPattern = RegExpValue; try { _currentRegex = new Regex(RegExpValue); } catch (ArgumentException) { await _regexProcessor.AddCurvyUnderlineAsync(); _occurrencesHighlighter.ResetTextProperties(); return; } _regexProcessor.ResetRegexProperties(); _current = _currentRegex.Matches(Text).Cast <Match>().ToArray(); bool previousIsCurrent = MatchesComparer.Equals(_current, _previous); const int symbolsToRemove = 2; if (_current.LastOrDefault()?.Value.Length > 1 && _latestOffset != -1 && LatestSymbolIndex <= _latestOffset) { await ResetValuesAsync(); } else if (_current.LastOrDefault()?.Value.Length == 1 && _latestOffset != -1 && LatestSymbolIndex < _latestOffset) { await ResetValuesAsync(); } else if (_current.LastOrDefault()?.Index + _current.LastOrDefault()?.Length != Text.Length - symbolsToRemove && previousIsCurrent) { ResetLatestInputProperties(); } else if (_current.ContainsInStart(_previous) && _current.Length > _previous.Length) { ResetLatestInputProperties(); UpdateValues(); } else if (!previousIsCurrent) { await ResetValuesAsync(); } _previous = _current; } }