extremely simplified version of backspace detection logic... getting a good night's sleep does wonders you know ;)
MODIFY
WalletWasabi.Fluent/Behaviors/TagBoxAutoCompleteBoxBehavior.cs
WalletWasabi.Fluent/Behaviors/TagBoxAutoCompleteBoxBehavior.cs
@@ -8,7 +8,6 @@ using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Threading;
using Avalonia.Xaml.Interactivity;
-using WalletWasabi.Fluent.Helpers;
namespace WalletWasabi.Fluent.Behaviors
{
@@ -24,8 +23,9 @@ namespace WalletWasabi.Fluent.Behaviors
AvaloniaProperty.Register<SplitViewAutoBehavior, Action>(nameof(BackspaceAndEmptyTextAction));
private IDisposable? _disposable;
- private const int BackspaceStackCapacity = 2;
- private readonly DropOutStack<string> _backspaceStack = new DropOutStack<string>(BackspaceStackCapacity);
+
+ private bool _bs1;
+ private bool _bs2;
public IEnumerable<string> Suggestions
{
@@ -69,24 +69,16 @@ namespace WalletWasabi.Fluent.Behaviors
private void OnTextInput(object? sender, TextInputEventArgs e)
{
- if (AssociatedObject is null)
- {
- return;
- }
+ if (AssociatedObject is null) return;
if (!Suggestions.Any(x =>
x.StartsWith(AssociatedObject.SearchText ?? "", true, CultureInfo.CurrentCulture)))
- {
e.Handled = true;
}
- }
private void OnDropDownClosed(object? sender, EventArgs e)
{
- if (AssociatedObject is null)
- {
- return;
- }
+ if (AssociatedObject is null) return;
var currentText = AssociatedObject.Text ?? "";
var selItem = AssociatedObject.SelectedItem as string;
@@ -98,18 +90,21 @@ namespace WalletWasabi.Fluent.Behaviors
CommitTextAction?.Invoke(currentText.Trim());
AssociatedObject.ClearValue(AutoCompleteBox.SelectedItemProperty);
- _backspaceStack.Clear();
+ BackspaceLogicClear();
Dispatcher.UIThread.Post(() => { AssociatedObject.ClearValue(AutoCompleteBox.TextProperty); });
}
- private void OnTextChanged(object? sender, EventArgs e)
- {
- if (AssociatedObject is null)
+ private void BackspaceLogicClear()
{
- return;
+ _bs1 = false;
+ _bs2 = false;
}
+ private void OnTextChanged(object? sender, EventArgs e)
+ {
+ if (AssociatedObject is null) return;
+
var currentText = AssociatedObject.Text ?? "";
var currentTextTrimmed = currentText.Trim();
@@ -120,7 +115,7 @@ namespace WalletWasabi.Fluent.Behaviors
CommitTextAction?.Invoke(currentTextTrimmed);
- _backspaceStack.Clear();
+ BackspaceLogicClear();
Dispatcher.UIThread.Post(() => { AssociatedObject?.ClearValue(AutoCompleteBox.TextProperty); });
}
@@ -131,26 +126,21 @@ namespace WalletWasabi.Fluent.Behaviors
var str = AssociatedObject?.Text ?? "";
- _backspaceStack.Push(str);
+ _bs2 = _bs1;
+ _bs1 = str.Length == 0;
var strTrimmed = str.Trim();
- var containsTwoItems = _backspaceStack.Items.Length >= BackspaceStackCapacity;
- var p1 = containsTwoItems ? _backspaceStack.Items[0] : "";
- var p2 = containsTwoItems ? _backspaceStack.Items[1] : "";
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
switch (e.Key)
{
- case Key.Back when string.IsNullOrEmpty(p1) && string.IsNullOrEmpty(p2):
+ case Key.Back when _bs1 && _bs2:
BackspaceAndEmptyTextAction?.Invoke();
break;
case Key.Enter when !string.IsNullOrEmpty(strTrimmed):
- if (!Suggestions.Any(x => x.Equals(strTrimmed, StringComparison.InvariantCultureIgnoreCase)))
- {
- break;
- }
+ if (!Suggestions.Any(x => x.Equals(strTrimmed, StringComparison.InvariantCultureIgnoreCase))) break;
- _backspaceStack.Clear();
+ BackspaceLogicClear();
CommitTextAction?.Invoke(strTrimmed);
Dispatcher.UIThread.Post(() => { AssociatedObject?.ClearValue(AutoCompleteBox.TextProperty); });
@@ -169,7 +159,7 @@ namespace WalletWasabi.Fluent.Behaviors
AssociatedObject.TextChanged -= OnTextChanged;
_disposable?.Dispose();
- _backspaceStack.Clear();
+ BackspaceLogicClear();
}
}
}
\ No newline at end of file

DELETE
WalletWasabi.Fluent/Helpers/DropOutStack.cs
-namespace WalletWasabi.Fluent.Helpers
-{
- /// <summary>
- /// A stack that retains only the last items it can store
- /// and removes the older entries automatically.
- /// </summary>
- public class DropOutStack<T>
- {
- private int _top = 0;
- private readonly int _capacity;
-
- public DropOutStack(int capacity)
- {
- _capacity = capacity;
- Items = new T[_capacity];
- }
-
- public void Push(T item)
- {
- Items[_top] = item;
- _top = (_top + 1) % Items.Length;
- }
-
- public T Pop()
- {
- _top = (Items.Length + _top - 1) % Items.Length;
- return Items[_top];
- }
-
- public T[] Items { get; private set; }
-
- public void Clear()
- {
- _top = 0;
- Items = new T[_capacity];
- }
- }
-}
\ No newline at end of file

extremely simplified version of backspace detection logic... getting a good night's sleep does wonders you know ;)