Public Access
Desktop: rebuild the hosts board once the typing in the find box pauses, not once a letter
This commit is contained in:
1 parent
8759b12d47
commit
24c18205c3
3 files changed
+94
-1
No files matched your search
@@ -230,9 +230,13 @@
|
||||
|
||||
Ctrl+K is named on it because the palette is the other way to reach a host by typing, and somebody
|
||||
who has found this box should know about the one that also connects on Enter.
|
||||
|
||||
One way, and passed back by the code-behind once the typing pauses: every change to the filter
|
||||
rebuilds the board's sections and their cards, and a name typed at speed used to do that once a
|
||||
letter. The view model still filters the moment it is told. See HostsScreen.OnFilterTyped.
|
||||
-->
|
||||
<Border Grid.Row="1" Margin="26,0,26,16">
|
||||
<TextBox x:Name="HostFilter" Text="{Binding HostFilter}" Height="40" CornerRadius="10"
|
||||
<TextBox x:Name="HostFilter" Text="{Binding HostFilter, Mode=OneWay}" Height="40" CornerRadius="10"
|
||||
FontFamily="{StaticResource MonoFont}"
|
||||
PlaceholderText="Find a host by name, address or note… · Ctrl+K searches and connects" />
|
||||
</Border>
|
||||
|
||||
@@ -106,6 +106,48 @@ internal sealed partial class HostsScreen : UserControl
|
||||
Board.AddHandler(ContextRequestedEvent, OnContextRequested, RoutingStrategies.Tunnel);
|
||||
|
||||
WireTheBand();
|
||||
|
||||
HostFilter.TextChanged += OnFilterTyped;
|
||||
}
|
||||
|
||||
/// <summary>How long the find box waits for the typing to pause before the board is rebuilt.</summary>
|
||||
private static readonly TimeSpan FilterPause = TimeSpan.FromMilliseconds(150);
|
||||
|
||||
/// <summary>The wait itself, replaceable so a test can say when a pause is over rather than sleep through one.</summary>
|
||||
internal Func<TimeSpan, Task> Pause { get; set; } = static span => Task.Delay(span);
|
||||
|
||||
/// <summary>How many times the find box has changed, so a wait can tell it is no longer the latest.</summary>
|
||||
private int typed;
|
||||
|
||||
/// <summary>Hands the find box's text to the vault once the typing pauses.</summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Every change to the filter rebuilds the board's sections and every card in them, and a name typed at
|
||||
/// speed used to do that once a letter. Now it is done once, with the whole of what was typed.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// A wait rather than a binding delay, and on the dispatcher's own queue: the box is bound one way, so a
|
||||
/// filter the vault sets itself — cleared, or restored — still lands in the box at once, and the
|
||||
/// change it makes to the box comes back here as the same text, which changes nothing.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
private void OnFilterTyped(object? sender, TextChangedEventArgs e) =>
|
||||
_ = PassTheFilterOnAsync(HostFilter.Text ?? string.Empty, ++typed);
|
||||
|
||||
private async Task PassTheFilterOnAsync(string text, int keystroke)
|
||||
{
|
||||
await Pause(FilterPause).ConfigureAwait(true);
|
||||
|
||||
// A later letter has its own wait, and it is the one that speaks.
|
||||
if (keystroke != typed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Vault is { } vault && !string.Equals(vault.HostFilter, text, StringComparison.Ordinal))
|
||||
{
|
||||
vault.HostFilter = text;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The band's own wiring, and the two keys that go with a set.</summary>
|
||||
|
||||
Reference in new issue
Block a user