feat: support paste.

This commit is contained in:
rabbitism
2024-11-06 14:38:39 +08:00
parent b4cc0f8f27
commit 6ef0cf9e1c
2 changed files with 112 additions and 1 deletions

View File

@@ -159,8 +159,30 @@ public class PinCode: TemplatedControl
};
}
protected void OnPreviewKeyDown(KeyEventArgs e)
protected async void OnPreviewKeyDown(KeyEventArgs e)
{
TextBox b = new TextBox();
var pasteKeys = Application.Current?.PlatformSettings.HotkeyConfiguration.Paste;
if (pasteKeys?.Any(a => a.Matches(e)) == true)
{
var clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
var text = await clipboard.GetTextAsync();
if (text is not null)
{
var newText = text.Where(c => Valid(c, Mode)).Take(Count).ToArray();
for (int i = 0; i < newText.Length; i++)
{
Digits[i] = newText[i].ToString();
var presenter = _itemsControl?.ContainerFromIndex(i) as PinCodeItem;
if (presenter is not null)
{
presenter.Focus();
presenter.Text = newText[i].ToString();
}
}
}
return;
}
if (e.Key == Key.Tab && e.Source is PinCodeItem)
{
_currentIndex = MathHelpers.SafeClamp(_currentIndex, 0, Count - 1);