Fix caret positioning
DELETE
WalletWasabi.Gui/Behaviors/PutCursorAtEndTextBoxBehavior.cs
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Threading;
-using Avalonia.Xaml.Interactivity;
-using System;
-using System.Reactive.Disposables;
-using System.Threading.Tasks;
-
-namespace WalletWasabi.Gui.Behaviors
-{
- internal class PutCursorAtEndTextBoxBehavior: Behavior<TextBox>
- {
- private TextBox _textBox;
-
- protected override void OnAttached()
- {
- base.OnAttached();
-
- _textBox = AssociatedObject as TextBox;
-
- if (_textBox == null)
- {
- return;
- }
- _textBox.PropertyChanged += TextInput;
- }
-
- protected override void OnDetaching()
- {
- if (_textBox == null)
- {
- return;
- }
- _textBox.PropertyChanged -= TextInput;
-
- base.OnDetaching();
- }
-
- private void TextInput(object sender, AvaloniaPropertyChangedEventArgs args)
- {
- if(args.Property.Name == "Text")
- Task.Delay(100).ContinueWith(x=>
- Dispatcher.UIThread.InvokeAsync(()=>_textBox.CaretIndex = _textBox.Text.Length + 1));
- }
- }
-}
\ No newline at end of file

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletView.xaml
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletView.xaml
</StackPanel>
<controls:ExtendedTextBox Text="{Binding WalletName}" Watermark="Wallet Name" UseFloatingWatermark="True" />
<TextBox Text="{Binding Password}" Watermark="Password" PasswordChar="*" UseFloatingWatermark="True" />
- <controls:ExtendedTextBox Text="{Binding MnemonicWords}" Watermark="MnemonicWords" UseFloatingWatermark="True" >
+ <controls:ExtendedTextBox Text="{Binding MnemonicWords}" Watermark="MnemonicWords" UseFloatingWatermark="True" CaretIndex="{Binding CaretIndex, Mode=TwoWay}">
<i:Interaction.Behaviors>
<behaviors:MnemonicSuggestionBehavior SuggestionItems="{Binding Suggestions}" />
- <behaviors:PutCursorAtEndTextBoxBehavior />
</i:Interaction.Behaviors>
</controls:ExtendedTextBox>
<ItemsControl Items="{Binding Suggestions}">

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletViewModel.cs
@@ -19,6 +19,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
{
internal class RecoverWalletViewModel : CategoryViewModel
{
+ private int _caretIndex;
private string _password;
private string _mnemonicWords;
private string _walletName;
@@ -28,6 +29,8 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
public RecoverWalletViewModel(WalletManagerViewModel owner) : base("Recover Wallet")
{
+ MnemonicWords = "";
+
RecoverCommand = ReactiveCommand.Create(() =>
{
WalletName = Guard.Correct(WalletName);
@@ -81,6 +84,15 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
}
}
});
+
+ this.WhenAnyValue(x => x.CaretIndex).Subscribe(_ =>
+ {
+ if(CaretIndex != MnemonicWords.Length)
+ {
+ CaretIndex = MnemonicWords.Length;
+ }
+ });
+
_suggestions = new ObservableCollection<MnemonicViewModel>();
}
@@ -120,6 +132,12 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
set { this.RaiseAndSetIfChanged(ref _validationMessage, value); }
}
+ public int CaretIndex
+ {
+ get { return _caretIndex; }
+ set { this.RaiseAndSetIfChanged(ref _caretIndex, value); }
+ }
+
public ReactiveCommand RecoverCommand { get; }
public void OnTermsClicked()
@@ -142,7 +160,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
base.OnCategorySelected();
Password = null;
- MnemonicWords = null;
+ MnemonicWords = "";
WalletName = Utils.GetNextWalletName();
TermsAccepted = false;
ValidationMessage = null;
@@ -176,8 +194,10 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
string[] words = MnemonicWords.Split(' ', StringSplitOptions.RemoveEmptyEntries);
words[words.Length-1] = word;
MnemonicWords = string.Join(' ', words) + " ";
- Task.Delay(50).ContinueWith(x=>
- Dispatcher.UIThread.InvokeAsync(()=>_suggestions.Clear()));
+
+ CaretIndex = MnemonicWords.Length;
+
+ Suggestions.Clear();
}
private static IEnumerable<string> EnglishWords = Wordlist.English.GetWords();

Fix caret positioning