private bool IsCaretOutsideItemBounds( Model model, SnapshotPoint caretPoint, CompletionItem item, Dictionary<TextSpan, string> textSpanToText, Dictionary<TextSpan, ViewTextSpan> textSpanToViewSpan) { // Easy first check. See if the caret point is before the start of the item. if (!textSpanToViewSpan.TryGetValue(item.Span, out var filterSpanInViewBuffer)) { filterSpanInViewBuffer = model.GetViewBufferSpan(item.Span); textSpanToViewSpan[item.Span] = filterSpanInViewBuffer; } if (caretPoint < filterSpanInViewBuffer.TextSpan.Start) { return true; } var textSnapshot = caretPoint.Snapshot; var currentText = model.GetCurrentTextInSnapshot(item.Span, textSnapshot, textSpanToText); var currentTextSpan = new TextSpan(filterSpanInViewBuffer.TextSpan.Start, currentText.Length); return !currentTextSpan.IntersectsWith(caretPoint); }
private bool IsFilterTextEmpty( Model model, SnapshotPoint caretPoint, CompletionItem item, Dictionary <TextSpan, string> textSpanToText, Dictionary <TextSpan, ViewTextSpan> textSpanToViewSpan) { // Easy first check. See if the caret point is before the start of the item. if (!textSpanToViewSpan.TryGetValue(item.Span, out var filterSpanInViewBuffer)) { filterSpanInViewBuffer = model.GetViewBufferSpan(item.Span); textSpanToViewSpan[item.Span] = filterSpanInViewBuffer; } if (caretPoint < filterSpanInViewBuffer.TextSpan.Start) { return(true); } var textSnapshot = caretPoint.Snapshot; var currentText = model.GetCurrentTextInSnapshot(item.Span, textSnapshot, textSpanToText); var currentTextSpan = new TextSpan(filterSpanInViewBuffer.TextSpan.Start, currentText.Length); return(currentText.Length == 0); }
private bool IsHardSelection( Model model, CompletionItem bestFilterMatch, SnapshotPoint caretPosition, CompletionHelper completionHelper, CompletionFilterReason filterReason) { var itemViewSpan = model.GetViewBufferSpan(bestFilterMatch.Span); var fullFilterText = model.GetCurrentTextInSnapshot(itemViewSpan, caretPosition.Snapshot, endPoint: null); var textSpan = itemViewSpan.TextSpan; // Switch to soft selection, if user moved caret to the start of a non-empty filter span. // This prevents commiting if user types a commit character at this position later, but // still has the list if user types filter character // i.e. blah| -> |blah -> !|blah // We want the filter span non-empty because we still want hard selection in the following case: // // A a = new | if (caretPosition == textSpan.Start && textSpan.Length > 0) { return(false); } return(ItemManager.IsHardSelection(fullFilterText, model.Trigger.Kind, bestFilterMatch, completionHelper, filterReason, this.Controller.GetRecentItems(), model.UseSuggestionMode)); }
private bool IsCaretOutsideItemBounds( Model model, SnapshotPoint caretPoint, PresentationItem item, Dictionary <TextSpan, string> textSpanToText, Dictionary <TextSpan, ViewTextSpan> textSpanToViewSpan) { // Easy first check. See if the caret point is before the start of the item. ViewTextSpan filterSpanInViewBuffer; if (!textSpanToViewSpan.TryGetValue(item.Item.Span, out filterSpanInViewBuffer)) { filterSpanInViewBuffer = model.GetViewBufferSpan(item.Item.Span); textSpanToViewSpan[item.Item.Span] = filterSpanInViewBuffer; } if (caretPoint < filterSpanInViewBuffer.TextSpan.Start) { return(true); } var textSnapshot = caretPoint.Snapshot; var currentText = model.GetCurrentTextInSnapshot(item.Item.Span, textSnapshot, textSpanToText); var currentTextSpan = new TextSpan(filterSpanInViewBuffer.TextSpan.Start, currentText.Length); return(!currentTextSpan.IntersectsWith(caretPoint)); }
private bool IsHardSelection( Model model, CompletionItem bestFilterMatch, SnapshotPoint caretPosition, CompletionHelper completionHelper, CompletionFilterReason reason) { if (bestFilterMatch == null || model.UseSuggestionMode) { return(false); } var textSnapshot = caretPosition.Snapshot; // We don't have a builder and we have a best match. Normally this will be hard // selected, except for a few cases. Specifically, if no filter text has been // provided, and this is not a preselect match then we will soft select it. This // happens when the completion list comes up implicitly and there is something in // the MRU list. In this case we do want to select it, but not with a hard // selection. Otherwise you can end up with the following problem: // // dim i as integer =<space> // // Completion will comes up after = with 'integer' selected (Because of MRU). We do // not want 'space' to commit this. var itemViewSpan = model.GetViewBufferSpan(bestFilterMatch.Span); var fullFilterText = model.GetCurrentTextInSnapshot(itemViewSpan, textSnapshot, endPoint: null); var trigger = model.Trigger; var shouldSoftSelect = ShouldSoftSelectItem(bestFilterMatch, fullFilterText, trigger); if (shouldSoftSelect) { return(false); } // If the user moved the caret left after they started typing, the 'best' match may not match at all // against the full text span that this item would be replacing. if (!MatchesFilterText(completionHelper, bestFilterMatch, fullFilterText, trigger, reason, this.Controller.GetRecentItems())) { return(false); } // Switch to soft selection, if user moved caret to the start of a non-empty filter span. // This prevents commiting if user types a commit character at this position later, but // still has the list if user types filter character // i.e. blah| -> |blah -> !|blah // We want the filter span non-empty because we still want hard selection in the following case: // // A a = new | if (caretPosition == itemViewSpan.TextSpan.Start && itemViewSpan.TextSpan.Length > 0) { return(false); } // There was either filter text, or this was a preselect match. In either case, we // can hard select this. return(true); }
private TextSpan GetCurrentItemSpan(CompletionItem item, Model model) { var originalSpanInView = model.GetViewBufferSpan(item.Span); var currentSpanInView = model.GetCurrentSpanInSnapshot(originalSpanInView, this.TextView.TextBuffer.CurrentSnapshot); var newStart = item.Span.Start + (currentSpanInView.Span.Start - originalSpanInView.TextSpan.Start); return(new TextSpan(newStart, currentSpanInView.Length)); }
private string GetTextTypedSoFar(Model model, CompletionItem selectedItem) { var textSnapshot = this.TextView.TextSnapshot; var viewSpan = model.GetViewBufferSpan(selectedItem.Span); var filterText = model.GetCurrentTextInSnapshot( viewSpan, textSnapshot, GetCaretPointInViewBuffer()); return(filterText); }
private bool IsHardSelection( Model model, PresentationItem bestFilterMatch, ITextSnapshot textSnapshot, CompletionHelper completionRules, CompletionTrigger trigger, CompletionFilterReason reason) { if (model.SuggestionModeItem != null) { return(bestFilterMatch != null && bestFilterMatch.Item.DisplayText == model.SuggestionModeItem.Item.DisplayText); } if (bestFilterMatch == null || model.UseSuggestionMode) { return(false); } // We don't have a builder and we have a best match. Normally this will be hard // selected, except for a few cases. Specifically, if no filter text has been // provided, and this is not a preselect match then we will soft select it. This // happens when the completion list comes up implicitly and there is something in // the MRU list. In this case we do want to select it, but not with a hard // selection. Otherwise you can end up with the following problem: // // dim i as integer =<space> // // Completion will comes up after = with 'integer' selected (Because of MRU). We do // not want 'space' to commit this. var viewSpan = model.GetViewBufferSpan(bestFilterMatch.Item.Span); var fullFilterText = model.GetCurrentTextInSnapshot(viewSpan, textSnapshot, endPoint: null); var shouldSoftSelect = completionRules.ShouldSoftSelectItem(bestFilterMatch.Item, fullFilterText, trigger); if (shouldSoftSelect) { return(false); } // If the user moved the caret left after they started typing, the 'best' match may not match at all // against the full text span that this item would be replacing. if (!completionRules.MatchesFilterText(bestFilterMatch.Item, fullFilterText, trigger, reason, this.Controller.GetRecentItems())) { return(false); } // There was either filter text, or this was a preselect match. In either case, we // can hard select this. return(true); }
private bool IsHardSelection( Model model, PresentationItem bestFilterMatch, ITextSnapshot textSnapshot, CompletionHelper completionHelper, CompletionTrigger trigger, CompletionFilterReason reason) { if (model.SuggestionModeItem != null) { return bestFilterMatch != null && bestFilterMatch.Item.DisplayText == model.SuggestionModeItem.Item.DisplayText; } if (bestFilterMatch == null || model.UseSuggestionMode) { return false; } // We don't have a builder and we have a best match. Normally this will be hard // selected, except for a few cases. Specifically, if no filter text has been // provided, and this is not a preselect match then we will soft select it. This // happens when the completion list comes up implicitly and there is something in // the MRU list. In this case we do want to select it, but not with a hard // selection. Otherwise you can end up with the following problem: // // dim i as integer =<space> // // Completion will comes up after = with 'integer' selected (Because of MRU). We do // not want 'space' to commit this. var viewSpan = model.GetViewBufferSpan(bestFilterMatch.Item.Span); var fullFilterText = model.GetCurrentTextInSnapshot(viewSpan, textSnapshot, endPoint: null); var shouldSoftSelect = ShouldSoftSelectItem(bestFilterMatch.Item, fullFilterText, trigger); if (shouldSoftSelect) { return false; } // If the user moved the caret left after they started typing, the 'best' match may not match at all // against the full text span that this item would be replacing. if (!MatchesFilterText(completionHelper, bestFilterMatch.Item, fullFilterText, trigger, reason, this.Controller.GetRecentItems())) { return false; } // There was either filter text, or this was a preselect match. In either case, we // can hard select this. return true; }
private TextSpan GetCurrentItemSpan(CompletionItem item, Model model) { var originalSpanInView = model.GetViewBufferSpan(item.Span); var currentSpanInView = model.GetCurrentSpanInSnapshot(originalSpanInView, this.TextView.TextBuffer.CurrentSnapshot); var newStart = item.Span.Start + (currentSpanInView.Span.Start - originalSpanInView.TextSpan.Start); return new TextSpan(newStart, currentSpanInView.Length); }
private bool IsHardSelection( Model model, CompletionItem bestFilterMatch, SnapshotPoint caretPosition, CompletionHelper completionHelper, CompletionFilterReason reason) { if (bestFilterMatch == null || model.UseSuggestionMode) { return false; } var textSnapshot = caretPosition.Snapshot; // We don't have a builder and we have a best match. Normally this will be hard // selected, except for a few cases. Specifically, if no filter text has been // provided, and this is not a preselect match then we will soft select it. This // happens when the completion list comes up implicitly and there is something in // the MRU list. In this case we do want to select it, but not with a hard // selection. Otherwise you can end up with the following problem: // // dim i as integer =<space> // // Completion will comes up after = with 'integer' selected (Because of MRU). We do // not want 'space' to commit this. var itemViewSpan = model.GetViewBufferSpan(bestFilterMatch.Span); var fullFilterText = model.GetCurrentTextInSnapshot(itemViewSpan, textSnapshot, endPoint: null); var trigger = model.Trigger; var shouldSoftSelect = ShouldSoftSelectItem(bestFilterMatch, fullFilterText, trigger); if (shouldSoftSelect) { return false; } // If the user moved the caret left after they started typing, the 'best' match may not match at all // against the full text span that this item would be replacing. if (!MatchesFilterText(completionHelper, bestFilterMatch, fullFilterText, trigger, reason, this.Controller.GetRecentItems())) { return false; } // Switch to soft selection, if user moved caret to the start of a non-empty filter span. // This prevents commiting if user types a commit character at this position later, but still has the list if user types filter character // i.e. blah| -> |blah -> !|blah // We want the filter span non-empty because we still want hard selection in the following case: // // A a = new | if (caretPosition == itemViewSpan.TextSpan.Start && itemViewSpan.TextSpan.Length > 0) { return false; } // There was either filter text, or this was a preselect match. In either case, we // can hard select this. return true; }