private Model SetModelSelectedItemInBackground(
                Model model,
                Func<Model, CompletionItem> selector)
            {
                if (model == null)
                {
                    return null;
                }

                // Switch to hard selection.
                var selectedItem = selector(model);
                Contract.ThrowIfFalse(model.TotalItems.Contains(selectedItem) || model.DefaultBuilder == selectedItem);

                if (model.FilteredItems.Contains(selectedItem))
                {
                    // Easy case, just set the selected item that's already in the filtered items
                    // list.

                    return model.WithSelectedItem(selector(model))
                                .WithHardSelection(true);
                }
                else
                {
                    // Item wasn't in the filtered list, so we need to recreate the filtered list
                    // with that item in it.
                    var filteredItemsSet = new HashSet<CompletionItem>(model.FilteredItems,
                        ReferenceEqualityComparer.Instance);

                    var newFilteredItems = model.TotalItems.Where(
                        i => filteredItemsSet.Contains(i) || i == selectedItem).ToList();
                    return model.WithFilteredItems(newFilteredItems)
                                .WithSelectedItem(selectedItem)
                                .WithHardSelection(true);
                }
            }
            private Model HandleDeletionTrigger(
                Model model, CompletionFilterReason filterReason, List <FilterResult> filterResults)
            {
                if (filterReason == CompletionFilterReason.Insertion &&
                    !filterResults.Any(r => r.MatchedFilterText))
                {
                    // The user has typed something, but nothing in the actual list matched what
                    // they were typing.  In this case, we want to dismiss completion entirely.
                    // The thought process is as follows: we aggressively brough up completion
                    // to help them when they typed delete (in case they wanted to pick another
                    // item).  However, they're typing something that doesn't seem to match at all
                    // The completion list is just distracting at this point.
                    return(null);
                }

                FilterResult?bestFilterResult = null;
                int          matchCount       = 0;

                foreach (var currentFilterResult in filterResults.Where(r => r.MatchedFilterText))
                {
                    if (bestFilterResult == null ||
                        IsBetterDeletionMatch(currentFilterResult, bestFilterResult.Value))
                    {
                        // We had no best result yet, so this is now our best result.
                        bestFilterResult = currentFilterResult;
                        matchCount++;
                    }
                }

                // If we had a matching item, then pick the best of the matching items and
                // choose that one to be hard selected.  If we had no actual matching items
                // (which can happen if the user deletes down to a single character and we
                // include everything), then we just soft select the first item.

                var filteredItems = filterResults.Select(r => r.CompletionItem).AsImmutable();

                model = model.WithFilteredItems(filteredItems);

                if (bestFilterResult != null)
                {
                    // Only hard select this result if it's a prefix match
                    // We need to do this so that
                    // * deleting and retyping a dot in a member access does not change the
                    //   text that originally appeared before the dot
                    // * deleting through a word from the end keeps that word selected
                    // This also preserves the behavior the VB had through Dev12.
                    var hardSelect = bestFilterResult.Value.CompletionItem.FilterText.StartsWith(model.FilterText, StringComparison.CurrentCultureIgnoreCase);
                    return(model.WithSelectedItem(bestFilterResult.Value.CompletionItem)
                           .WithHardSelection(hardSelect)
                           .WithIsUnique(matchCount == 1));
                }
                else
                {
                    return(model.WithHardSelection(false)
                           .WithIsUnique(false));
                }
            }
            private Model HandleDeletionTrigger(
                Model model, CompletionFilterReason filterReason, List <FilterResult> filterResults)
            {
                if (filterReason == CompletionFilterReason.Insertion &&
                    !filterResults.Any(r => r.MatchedFilterText))
                {
                    // The user has typed something, but nothing in the actual list matched what
                    // they were typing.  In this case, we want to dismiss completion entirely.
                    // The thought process is as follows: we aggressively brough up completion
                    // to help them when they typed delete (in case they wanted to pick another
                    // item).  However, they're typing something that doesn't seem to match at all
                    // The completion list is just distracting at this point.
                    return(null);
                }

                FilterResult?bestFilterResult = null;
                int          matchCount       = 0;

                foreach (var currentFilterResult in filterResults.Where(r => r.MatchedFilterText))
                {
                    if (bestFilterResult == null ||
                        IsBetterDeletionMatch(currentFilterResult, bestFilterResult.Value))
                    {
                        // We had no best result yet, so this is now our best result.
                        bestFilterResult = currentFilterResult;
                        matchCount++;
                    }
                }

                // If we had a matching item, then pick the best of the matching items and
                // choose that one to be hard selected.  If we had no actual matching items
                // (which can happen if the user deletes down to a single character and we
                // include everything), then we just soft select the first item.

                var filteredItems = filterResults.Select(r => r.CompletionItem).AsImmutable();

                model = model.WithFilteredItems(filteredItems);

                if (bestFilterResult != null)
                {
                    return(model.WithSelectedItem(bestFilterResult.Value.CompletionItem)
                           .WithHardSelection(true)
                           .WithIsUnique(matchCount == 1));
                }
                else
                {
                    return(model.WithHardSelection(false)
                           .WithIsUnique(false));
                }
            }
            private Model SetModelBuilderStateInBackground(
                Model model,
                bool includeBuilder)
            {
                if (model == null)
                {
                    return null;
                }

                // We want to soft select if the user is switching the builder on, or if we were
                // already in soft select mode.
                var softSelect = includeBuilder || model.IsSoftSelection;

                // If the selected item is the builder, select the first filtered item instead.
                if (model.SelectedItem == model.DefaultSuggestionModeItem)
                {
                    return model.WithSelectedItem(model.FilteredItems.First())
                                .WithHardSelection(!softSelect);
                }

                return model.WithHardSelection(!softSelect).WithUseSuggestionMode(includeBuilder);
            }
Пример #5
0
            private Model SetModelBuilderStateInBackground(
                Model model,
                bool includeBuilder)
            {
                if (model == null)
                {
                    return(null);
                }

                // We want to soft select if the user is switching the builder on, or if we were
                // already in soft select mode.
                var softSelect = includeBuilder || model.IsSoftSelection;

                // If the selected item is the builder, select the first filtered item instead.
                if (model.SelectedItem == model.DefaultBuilder)
                {
                    return(model.WithSelectedItem(model.FilteredItems.First())
                           .WithHardSelection(!softSelect));
                }

                return(model.WithHardSelection(!softSelect).WithUseSuggestionCompletionMode(includeBuilder));
            }
Пример #6
0
            private Model HandleDeletionTrigger(Model model, List <FilterResult> filterResults)
            {
                FilterResult?bestFilterResult = null;
                int          matchCount       = 0;

                foreach (var currentFilterResult in filterResults.Where(r => r.MatchedFilterText))
                {
                    if (bestFilterResult == null ||
                        IsBetterDeletionMatch(currentFilterResult, bestFilterResult.Value))
                    {
                        // We had no best result yet, so this is now our best result.
                        bestFilterResult = currentFilterResult;
                        matchCount++;
                    }
                }

                // If we had a matching item, then pick the best of the matching items and
                // choose that one to be hard selected.  If we had no actual matching items
                // (which can happen if the user deletes down to a single character and we
                // include everything), then we just soft select the first item.

                var filteredItems = filterResults.Select(r => r.CompletionItem).AsImmutable();

                model = model.WithFilteredItems(filteredItems);

                if (bestFilterResult != null)
                {
                    return(model.WithSelectedItem(bestFilterResult.Value.CompletionItem)
                           .WithHardSelection(true)
                           .WithIsUnique(matchCount == 1));
                }
                else
                {
                    return(model.WithHardSelection(false)
                           .WithIsUnique(false));
                }
            }
Пример #7
0
            private Model SetModelBuilderStateInBackground(
                Model model,
                bool includeBuilder)
            {
                if (model == null)
                {
                    return(null);
                }

                // We want to soft select if the user is switching the builder on, or if we were
                // already in soft select mode.
                var softSelect = includeBuilder || model.IsSoftSelection;

                if (model.SelectedItemOpt == model.SuggestionModeItem &&
                    !includeBuilder)
                {
                    // Use had the builder selected, but turned off the builder.  Switch to the
                    // first filtered item.
                    model = model.WithSelectedItem(model.FilteredItems.First());
                }

                return(model.WithHardSelection(!softSelect)
                       .WithUseSuggestionMode(includeBuilder));
            }
            private Model SetModelSelectedItemInBackground(
                Model model,
                Func <Model, PresentationItem> selector)
            {
                if (model == null)
                {
                    return(null);
                }

                // Switch to hard selection.
                var selectedItem = selector(model);

                Contract.ThrowIfFalse(model.TotalItems.Contains(selectedItem) || model.DefaultSuggestionModeItem == selectedItem);

                if (model.FilteredItems.Contains(selectedItem))
                {
                    // Easy case, just set the selected item that's already in the filtered items
                    // list.

                    return(model.WithSelectedItem(selector(model))
                           .WithHardSelection(true));
                }
                else
                {
                    // Item wasn't in the filtered list, so we need to recreate the filtered list
                    // with that item in it.
                    var filteredItemsSet = new HashSet <PresentationItem>(model.FilteredItems,
                                                                          ReferenceEqualityComparer.Instance);

                    var newFilteredItems = model.TotalItems.Where(
                        i => filteredItemsSet.Contains(i) || i == selectedItem).ToImmutableArrayOrEmpty();
                    return(model.WithFilteredItems(newFilteredItems)
                           .WithSelectedItem(selectedItem)
                           .WithHardSelection(true));
                }
            }
            private Model SetModelBuilderStateInBackground(
                Model model,
                bool includeBuilder)
            {
                if (model == null)
                {
                    return null;
                }

                // We want to soft select if the user is switching the builder on, or if we were
                // already in soft select mode.
                var softSelect = includeBuilder || model.IsSoftSelection;

                if (model.SelectedItem == model.SuggestionModeItem &&
                    !includeBuilder)
                {
                    // Use had the builder selected, but turned off the builder.  Switch to the
                    // first filtered item.
                    model = model.WithSelectedItem(model.FilteredItems.First());
                }

                return model.WithHardSelection(!softSelect)
                            .WithUseSuggestionMode(includeBuilder);
            }
            private Model HandleDeletionTrigger(Model model, List<FilterResult> filterResults)
            {
                FilterResult? bestFilterResult = null;
                int matchCount = 0;
                foreach (var currentFilterResult in filterResults.Where(r => r.MatchedFilterText))
                {
                    if (bestFilterResult == null ||
                        IsBetterDeletionMatch(currentFilterResult, bestFilterResult.Value))
                    {
                        // We had no best result yet, so this is now our best result.
                        bestFilterResult = currentFilterResult;
                        matchCount++;
                    }
                }

                // If we had a matching item, then pick the best of the matching items and
                // choose that one to be hard selected.  If we had no actual matching items
                // (which can happen if the user deletes down to a single character and we
                // include everything), then we just soft select the first item.

                var filteredItems = filterResults.Select(r => r.PresentationItem).AsImmutable();
                model = model.WithFilteredItems(filteredItems);

                if (bestFilterResult != null)
                {
                    return model.WithSelectedItem(bestFilterResult.Value.PresentationItem)
                                .WithHardSelection(true)
                                .WithIsUnique(matchCount == 1);
                }
                else
                {
                    return model.WithHardSelection(false)
                                .WithIsUnique(false);
                }
            }