public IntellisenseSuggest CycleValue(TextInputState input, bool backward, string language) { string query = input.Text; int caret = input.Caret; var token = new MtgTolerantTokenizer(query).GetEditedToken(caret); if (token == null || token.Type.IsAny(TokenType.ModifierValue)) { return(null); } string userField = token.ParentField ?? string.Empty; bool isFieldInvalid = !Adapter.IsAnyField(userField) && !Adapter.IsUserField(userField); if (isFieldInvalid) { return(null); } string currentValue; if (!Adapter.IsSuggestAnalyzedIn(userField, language)) { token = token.PhraseStart ?? token; currentValue = StringEscaper.Unescape(token.GetPhraseText(query)); } else { currentValue = StringEscaper.Unescape(token.Value); } var snapshot = State; var allValues = snapshot.GetValuesCache(userField, language); if (allValues.Count == 0) { return(null); } var currentIndex = allValues.BinarySearchLastIndexOf(str => Str.Comparer.Compare(str, currentValue) <= 0); int increment = backward ? -1 : 1; var nextIndex = currentIndex + increment; if (nextIndex == allValues.Count) { nextIndex = 0; } else if (nextIndex == -1) { nextIndex = allValues.Count - 1; } var nextValue = allValues[nextIndex]; return(new IntellisenseSuggest(token, ReadOnlyList.From(nextValue), _allTokensAreValues)); }
private IReadOnlyList <string> getAnalyzedTokens(Token t, string queryStr) { if (t.Type.IsAny(TokenType.RegexBody)) { return(ReadOnlyList.From(t.Value)); } if (!t.Type.IsAny(TokenType.FieldValue)) { return(null); } string text = !t.IsPhrase || t.IsPhraseComplex || t.PhraseHasSlop ? t.Value : t.GetPhraseText(queryStr); var result = QueryParserAnalyzer .GetTokens(t.ParentField, StringEscaper.Unescape(text)) .Select(_ => _.Term) .ToReadOnlyList(); return(result); }