|
|
@ -43,6 +43,11 @@ public class CompletionWindow : CompletionWindowBase |
|
|
|
private PopupWithCustomPosition? _toolTip; |
|
|
|
private PopupWithCustomPosition? _toolTip; |
|
|
|
private ContentControl? _toolTipContent; |
|
|
|
private ContentControl? _toolTipContent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Max number of items in the completion list. |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
public int MaxListLength { get; set; } = 40; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Gets the completion list used in this completion window. |
|
|
|
/// Gets the completion list used in this completion window. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
@ -254,22 +259,41 @@ public class CompletionWindow : CompletionWindowBase |
|
|
|
Debug.WriteLine("CaretPositionChanged newText: " + newText); |
|
|
|
Debug.WriteLine("CaretPositionChanged newText: " + newText); |
|
|
|
|
|
|
|
|
|
|
|
// CompletionList.SelectItem(newText); |
|
|
|
// CompletionList.SelectItem(newText); |
|
|
|
|
|
|
|
|
|
|
|
Dispatcher.UIThread.Post(() => UpdateQuery(newText)); |
|
|
|
Dispatcher.UIThread.Post(() => UpdateQuery(newText)); |
|
|
|
|
|
|
|
// UpdateQuery(newText); |
|
|
|
|
|
|
|
|
|
|
|
IsVisible = CompletionList.ListBox!.ItemCount != 0; |
|
|
|
IsVisible = CompletionList.ListBox!.ItemCount != 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string? lastSearchTerm; |
|
|
|
|
|
|
|
private int lastCompletionLength; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Update the completion window's current search term. |
|
|
|
/// Update the completion window's current search term. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public void UpdateQuery(string searchTerm) |
|
|
|
public void UpdateQuery(string searchTerm) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var results = completionProvider.GetCompletions(searchTerm, 30, true); |
|
|
|
// Fast path if the search term starts with the last search term |
|
|
|
|
|
|
|
// and the last completion count was less than the max list length |
|
|
|
|
|
|
|
// (such we won't get new results by searching again) |
|
|
|
|
|
|
|
if (lastSearchTerm is not null |
|
|
|
|
|
|
|
&& searchTerm.StartsWith(lastSearchTerm) |
|
|
|
|
|
|
|
&& lastCompletionLength < MaxListLength) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CompletionList.SelectItem(searchTerm); |
|
|
|
|
|
|
|
lastSearchTerm = searchTerm; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var results = completionProvider.GetCompletions(searchTerm, MaxListLength, true); |
|
|
|
CompletionList.CompletionData.Clear(); |
|
|
|
CompletionList.CompletionData.Clear(); |
|
|
|
CompletionList.CompletionData.AddRange(results); |
|
|
|
CompletionList.CompletionData.AddRange(results); |
|
|
|
|
|
|
|
|
|
|
|
CompletionList.SelectItem(searchTerm, true); |
|
|
|
CompletionList.SelectItem(searchTerm, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastSearchTerm = searchTerm; |
|
|
|
|
|
|
|
lastCompletionLength = CompletionList.CompletionData.Count; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|