Ejemplo n.º 1
0
        private void SuggestionsProvidedHandler(
            ConsoleCommandVariant commandVariant,
            IReadOnlyList <string> suggestions,
            byte requestId)
        {
            if (this.lastSuggestionRequestId != requestId)
            {
                // not the callback on the latest request - ignore it
                return;
            }

            this.currentCommandVariant = commandVariant;

            if (suggestions is not null)
            {
                var sortedSuggestions = new List <string>(suggestions);
                sortedSuggestions.Sort(StringComparer.OrdinalIgnoreCase);
                this.currentSuggestions = sortedSuggestions.ToArray();
            }
            else
            {
                this.currentSuggestions = null;
            }

            this.suggestionCurrentIndex = this.FindCurrentSuggestionIndex();
            this.viewModelConsoleControl.SetSuggestions(this.currentSuggestions);
            if (this.currentSuggestions is not null)
            {
                this.viewModelConsoleControl.SuggestionsListSelectedItemIndex = this.suggestionCurrentIndex;
            }

            if (!this.IsSuggestionMode)
            {
                this.UpdateSuggestionsMenuAndGhost();
                return;
            }

            // select suggested text
            var suggestion = this.currentSuggestions?.Length > 0
                                 ? this.currentSuggestions[this.suggestionCurrentIndex]
                                 : string.Empty;

            this.SetSuggestedText(suggestion);

            if (this.currentSuggestions is not null &&
                this.currentSuggestions.Length == 1)
            {
                // reset suggestions as there are no other suggestions except the one which was set right now
                this.ExitSuggestionMode(resetSuggestions: true);
            }
        }
Ejemplo n.º 2
0
        private void SuggestionsProvidedHandler(
            ConsoleCommandVariant commandVariant,
            IReadOnlyList <string> suggestions,
            byte requestId)
        {
            if (this.lastSuggestionRequestId != requestId)
            {
                // not the callback on the latest request - ignore it
                return;
            }

            this.currentCommandVariant = commandVariant;

            this.currentSuggestions     = suggestions;
            this.suggestionCurrentIndex = 0;
            this.viewModelConsoleControl.SetSuggestions(suggestions);

            if (!this.IsSuggestionMode)
            {
                this.UpdateSuggestionsMenuAndGhost();
                return;
            }

            // select suggested text
            var suggestion = this.currentSuggestions?.Count > 0
                                 ? this.currentSuggestions[this.suggestionCurrentIndex]
                                 : string.Empty;

            this.SetSuggestedText(suggestion);

            if (this.currentSuggestions != null &&
                this.currentSuggestions.Count == 1)
            {
                // reset suggestions as there are no other suggestions except the one which was set right now
                this.ExitSuggestionMode(resetSuggestions: true);
            }
        }