mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
[PTRun]Add setting to disable input delay (#18724)
* [PTRun]Add setting to disable input delay * Address feedback and allow configuring delay * Address PR feedback
This commit is contained in:
@@ -36,6 +36,7 @@ namespace PowerLauncher
|
||||
private Timer _firstDeleteTimer = new Timer();
|
||||
private bool _coldStateHotkeyPressed;
|
||||
private bool _disposedValue;
|
||||
private IDisposable _reactiveSubscription;
|
||||
|
||||
public MainWindow(PowerToysRunSettings settings, MainViewModel mainVM)
|
||||
: this()
|
||||
@@ -159,13 +160,18 @@ namespace PowerLauncher
|
||||
SearchBox.QueryTextBox.DataContext = _viewModel;
|
||||
SearchBox.QueryTextBox.PreviewKeyDown += Launcher_KeyDown;
|
||||
|
||||
Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>(
|
||||
add => SearchBox.QueryTextBox.TextChanged += add,
|
||||
remove => SearchBox.QueryTextBox.TextChanged -= remove)
|
||||
.Do(@event => ClearAutoCompleteText((TextBox)@event.Sender))
|
||||
.Throttle(TimeSpan.FromMilliseconds(150))
|
||||
.Do(@event => Dispatcher.InvokeAsync(() => PerformSearchQuery((TextBox)@event.Sender)))
|
||||
.Subscribe();
|
||||
SetupSearchTextBoxReactiveness(_viewModel.GetSearchQueryResultsWithDelaySetting(), _viewModel.GetSearchInputDelaySetting());
|
||||
_viewModel.RegisterSettingsChangeListener(
|
||||
(s, prop_e) =>
|
||||
{
|
||||
if (prop_e.PropertyName == nameof(PowerToysRunSettings.SearchQueryResultsWithDelay) || prop_e.PropertyName == nameof(PowerToysRunSettings.SearchInputDelay))
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
SetupSearchTextBoxReactiveness(_viewModel.GetSearchQueryResultsWithDelaySetting(), _viewModel.GetSearchInputDelaySetting());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Set initial language flow direction
|
||||
SearchBox_UpdateFlowDirection();
|
||||
@@ -186,6 +192,32 @@ namespace PowerLauncher
|
||||
BringProcessToForeground();
|
||||
}
|
||||
|
||||
private void SetupSearchTextBoxReactiveness(bool showResultsWithDelay, int searchInputDelayMs)
|
||||
{
|
||||
if (_reactiveSubscription != null)
|
||||
{
|
||||
_reactiveSubscription.Dispose();
|
||||
_reactiveSubscription = null;
|
||||
}
|
||||
|
||||
SearchBox.QueryTextBox.TextChanged -= QueryTextBox_TextChanged;
|
||||
|
||||
if (showResultsWithDelay)
|
||||
{
|
||||
_reactiveSubscription = Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>(
|
||||
add => SearchBox.QueryTextBox.TextChanged += add,
|
||||
remove => SearchBox.QueryTextBox.TextChanged -= remove)
|
||||
.Do(@event => ClearAutoCompleteText((TextBox)@event.Sender))
|
||||
.Throttle(TimeSpan.FromMilliseconds(searchInputDelayMs))
|
||||
.Do(@event => Dispatcher.InvokeAsync(() => PerformSearchQuery((TextBox)@event.Sender)))
|
||||
.Subscribe();
|
||||
}
|
||||
else
|
||||
{
|
||||
SearchBox.QueryTextBox.TextChanged += QueryTextBox_TextChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void SuggestionsList_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var result = ((FrameworkElement)e.OriginalSource).DataContext;
|
||||
@@ -428,6 +460,13 @@ namespace PowerLauncher
|
||||
}
|
||||
}
|
||||
|
||||
private void QueryTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
var textBox = (TextBox)sender;
|
||||
ClearAutoCompleteText(textBox);
|
||||
PerformSearchQuery(textBox);
|
||||
}
|
||||
|
||||
private void ClearAutoCompleteText(TextBox textBox)
|
||||
{
|
||||
var text = textBox.Text;
|
||||
|
||||
@@ -105,6 +105,16 @@ namespace PowerLauncher
|
||||
_settings.UseCentralizedKeyboardHook = overloadSettings.Properties.UseCentralizedKeyboardHook;
|
||||
}
|
||||
|
||||
if (_settings.SearchQueryResultsWithDelay != overloadSettings.Properties.SearchQueryResultsWithDelay)
|
||||
{
|
||||
_settings.SearchQueryResultsWithDelay = overloadSettings.Properties.SearchQueryResultsWithDelay;
|
||||
}
|
||||
|
||||
if (_settings.SearchInputDelay != overloadSettings.Properties.SearchInputDelay)
|
||||
{
|
||||
_settings.SearchInputDelay = overloadSettings.Properties.SearchInputDelay;
|
||||
}
|
||||
|
||||
if (_settings.MaxResultsToShow != overloadSettings.Properties.MaximumNumberOfResults)
|
||||
{
|
||||
_settings.MaxResultsToShow = overloadSettings.Properties.MaximumNumberOfResults;
|
||||
|
||||
@@ -132,6 +132,11 @@ namespace PowerLauncher.ViewModel
|
||||
// SetCustomPluginHotkey();
|
||||
}
|
||||
|
||||
public void RegisterSettingsChangeListener(System.ComponentModel.PropertyChangedEventHandler handler)
|
||||
{
|
||||
_settings.PropertyChanged += handler;
|
||||
}
|
||||
|
||||
private void RegisterResultsUpdatedEvent()
|
||||
{
|
||||
foreach (var pair in PluginManager.GetPluginsForInterface<IResultUpdated>())
|
||||
@@ -1102,5 +1107,15 @@ namespace PowerLauncher.ViewModel
|
||||
_hotkeyTimer.Reset();
|
||||
return recordedTime;
|
||||
}
|
||||
|
||||
public bool GetSearchQueryResultsWithDelaySetting()
|
||||
{
|
||||
return _settings.SearchQueryResultsWithDelay;
|
||||
}
|
||||
|
||||
public int GetSearchInputDelaySetting()
|
||||
{
|
||||
return _settings.SearchInputDelay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,44 @@ namespace Wox.Infrastructure.UserSettings
|
||||
}
|
||||
}
|
||||
|
||||
private bool _searchQueryResultsWithDelay = true;
|
||||
|
||||
public bool SearchQueryResultsWithDelay
|
||||
{
|
||||
get
|
||||
{
|
||||
return _searchQueryResultsWithDelay;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_searchQueryResultsWithDelay != value)
|
||||
{
|
||||
_searchQueryResultsWithDelay = value;
|
||||
OnPropertyChanged(nameof(SearchQueryResultsWithDelay));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _searchInputDelay = 150;
|
||||
|
||||
public int SearchInputDelay
|
||||
{
|
||||
get
|
||||
{
|
||||
return _searchInputDelay;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_searchInputDelay != value)
|
||||
{
|
||||
_searchInputDelay = value;
|
||||
OnPropertyChanged(nameof(SearchInputDelay));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Language { get; set; } = "en";
|
||||
|
||||
public Theme Theme { get; set; } = Theme.System;
|
||||
|
||||
Reference in New Issue
Block a user