Пример #1
0
        private (string, AutocompleteSuggestionType) parseQuery(TextFieldInfo info)
        {
            if (string.IsNullOrEmpty(info.Text))
            {
                return(info.Text, AutocompleteSuggestionType.TimeEntries);
            }

            var querySymbols = info.ProjectId != null ? QuerySymbols.ProjectSelected : QuerySymbols.All;

            var stringToSearch     = info.Text.Substring(0, info.DescriptionCursorPosition);
            var indexOfQuerySymbol = stringToSearch.LastIndexOfAny(querySymbols);

            if (indexOfQuerySymbol >= 0)
            {
                var startingIndex = indexOfQuerySymbol + 1;
                var stringLength  = info.Text.Length - indexOfQuerySymbol - 1;
                var suggestion    =
                    stringToSearch[indexOfQuerySymbol] == QuerySymbols.Projects
                    ? AutocompleteSuggestionType.Projects
                    : AutocompleteSuggestionType.Tags;

                return(info.Text.Substring(startingIndex, stringLength), suggestion);
            }

            return(info.Text, AutocompleteSuggestionType.TimeEntries);
        }
Пример #2
0
        private static QueryInfo?searchByQuerySymbols(QueryTextSpan span, TextFieldInfo info)
        {
            var validQuerySymbols = info.ValidQuerySymbols();
            var text = span.Text;

            var possibleIndexOfQuerySymbol =
                text.Substring(0, span.CursorPosition)
                .Select((character, index) => ((int?)index, character))
                .Where(tuple => validQuerySymbols.Contains(tuple.Item2))
                .Select(tuple => tuple.Item1)
                .FirstOrDefault(querySymbolIndex =>
            {
                var previousIndex      = querySymbolIndex.Value - 1;
                var isValidSymbolIndex = previousIndex < 0 || Char.IsWhiteSpace(text[previousIndex]);

                return(isValidSymbolIndex);
            });

            if (possibleIndexOfQuerySymbol == null)
            {
                return(null);
            }

            var indexOfQuerySymbol = possibleIndexOfQuerySymbol.Value;
            var startingIndex      = indexOfQuerySymbol + 1;
            var stringLength       = text.Length - indexOfQuerySymbol - 1;
            var type      = getSuggestionType(text[indexOfQuerySymbol]);
            var queryText = text.Substring(startingIndex, stringLength);

            return(new QueryInfo(queryText, type));
        }
Пример #3
0
        public static QueryInfo ParseFieldInfo(TextFieldInfo info)
        {
            if (string.IsNullOrEmpty(info.Text))
            {
                return(emptyQueryInfo);
            }

            return(searchByQuerySymbols(info)
                   ?? getDefaultQueryInfo(info.Text));
        }
Пример #4
0
        public static QueryInfo ParseFieldInfo(TextFieldInfo info)
        {
            var querySpan = info.GetSpanWithCurrentTextCursor();

            if (string.IsNullOrEmpty(querySpan?.Text))
            {
                return(emptyQueryInfo);
            }

            return(searchByQuerySymbols(querySpan, info) ?? getDefaultQueryInfo(querySpan.Text));
        }
Пример #5
0
        private static QueryInfo?searchByQuerySymbols(TextFieldInfo info)
        {
            int    indexOfQuerySymbol = info.DescriptionCursorPosition;
            string stringToSearch;

            do
            {
                stringToSearch     = info.Text.Substring(0, indexOfQuerySymbol);
                indexOfQuerySymbol = stringToSearch.LastIndexOfAny(getQuerySymbols(info));
            } while (indexOfQuerySymbol > 0 && Char.IsWhiteSpace(stringToSearch[indexOfQuerySymbol - 1]) == false);

            if (indexOfQuerySymbol >= 0)
            {
                var startingIndex = indexOfQuerySymbol + 1;
                var stringLength  = info.Text.Length - indexOfQuerySymbol - 1;
                var type          = getSuggestionType(stringToSearch[indexOfQuerySymbol]);
                var text          = info.Text.Substring(startingIndex, stringLength);

                return(new QueryInfo(text, type));
            }

            return(null);
        }
Пример #6
0
 public IObservable <IEnumerable <AutocompleteSuggestion> > Query(TextFieldInfo info)
 {
     var(queryText, suggestionType) = parseQuery(info);
     return(Query(queryText, suggestionType));
 }
Пример #7
0
 public IObservable <IEnumerable <AutocompleteSuggestion> > Query(TextFieldInfo info)
 => Query(QueryInfo.ParseFieldInfo(info));
Пример #8
0
 private static char[] getQuerySymbols(TextFieldInfo info)
 => info.ProjectId.HasValue
         ? QuerySymbols.ProjectSelected
         : QuerySymbols.All;