mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
CmdPal: Remove support for "selection" TextToSuggest (#41956)
`TextToSuggest` has been nothing but pain. We need another approach. I'm leaving the code, but just disabled behind an env flag. Same as actions. Closes #41659
This commit is contained in:
@@ -32,10 +32,22 @@ public sealed partial class SearchBar : UserControl,
|
||||
private readonly DispatcherQueueTimer _debounceTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
|
||||
private bool _isBackspaceHeld;
|
||||
|
||||
// Inline text suggestions
|
||||
// In 0.4-0.5 we would replace the text of the search box with the TextToSuggest
|
||||
// This was really cool for navigating paths in run and pretty much nowhere else.
|
||||
// We'll have to try another approach, but for now, the code is still testable.
|
||||
// You can test this by setting the CMDPAL_ENABLE_SUGGESTION_SELECTION env var to 1
|
||||
private bool _inSuggestion;
|
||||
|
||||
private bool InSuggestion => _inSuggestion && IsTextToSuggestEnabled;
|
||||
|
||||
private string? _lastText;
|
||||
|
||||
private string? _deletedSuggestion;
|
||||
|
||||
// 0.6+ suggestions
|
||||
private string? _textToSuggest;
|
||||
|
||||
public PageViewModel? CurrentPageViewModel
|
||||
{
|
||||
get => (PageViewModel?)GetValue(CurrentPageViewModelProperty);
|
||||
@@ -194,7 +206,23 @@ public sealed partial class SearchBar : UserControl,
|
||||
}
|
||||
else if (e.Key == VirtualKey.Right)
|
||||
{
|
||||
if (_inSuggestion)
|
||||
// Check if the "replace search text with suggestion" feature from 0.4-0.5 is enabled.
|
||||
// If it isn't, then only use the suggestion when the caret is at the end of the input.
|
||||
if (!IsTextToSuggestEnabled)
|
||||
{
|
||||
if (_textToSuggest != null &&
|
||||
FilterBox.SelectionStart == FilterBox.Text.Length)
|
||||
{
|
||||
FilterBox.Text = _textToSuggest;
|
||||
FilterBox.Select(_textToSuggest.Length, 0);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Here, we're using the "replace search text with suggestion" feature.
|
||||
if (InSuggestion)
|
||||
{
|
||||
_inSuggestion = false;
|
||||
_lastText = null;
|
||||
@@ -208,7 +236,7 @@ public sealed partial class SearchBar : UserControl,
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
if (_inSuggestion)
|
||||
if (InSuggestion)
|
||||
{
|
||||
if (
|
||||
e.Key == VirtualKey.Back ||
|
||||
@@ -294,7 +322,7 @@ public sealed partial class SearchBar : UserControl,
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inSuggestion)
|
||||
if (InSuggestion)
|
||||
{
|
||||
// Logger.LogInfo($"-- skipping, in suggestion --");
|
||||
return;
|
||||
@@ -316,7 +344,7 @@ public sealed partial class SearchBar : UserControl,
|
||||
|
||||
private void DoFilterBoxUpdate()
|
||||
{
|
||||
if (_inSuggestion)
|
||||
if (InSuggestion)
|
||||
{
|
||||
// Logger.LogInfo($"--- skipping ---");
|
||||
return;
|
||||
@@ -368,6 +396,12 @@ public sealed partial class SearchBar : UserControl,
|
||||
|
||||
public void Receive(UpdateSuggestionMessage message)
|
||||
{
|
||||
if (!IsTextToSuggestEnabled)
|
||||
{
|
||||
_textToSuggest = message.TextToSuggest;
|
||||
return;
|
||||
}
|
||||
|
||||
var suggestion = message.TextToSuggest;
|
||||
|
||||
_queue.TryEnqueue(new(() =>
|
||||
@@ -457,4 +491,15 @@ public sealed partial class SearchBar : UserControl,
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private static bool IsTextToSuggestEnabled => _textToSuggestEnabled.Value;
|
||||
|
||||
private static Lazy<bool> _textToSuggestEnabled = new(() => QueryTextToSuggestEnabled());
|
||||
|
||||
private static bool QueryTextToSuggestEnabled()
|
||||
{
|
||||
var env = System.Environment.GetEnvironmentVariable("CMDPAL_ENABLE_SUGGESTION_SELECTION");
|
||||
return !string.IsNullOrEmpty(env) &&
|
||||
(env == "1" || env.Equals("true", System.StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user