From 52ba6459c4727dba9ff2aaee54afaf434cb0eb62 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 16 Mar 2024 17:07:34 +0800 Subject: [PATCH] feat: move dot to text input handling. fix numpad return key in num mode. --- src/Ursa.Themes.Semi/Controls/NumPad.axaml | 29 +++++++++++--------- src/Ursa/Controls/IPv4Box.cs | 31 ++++++++-------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/Ursa.Themes.Semi/Controls/NumPad.axaml b/src/Ursa.Themes.Semi/Controls/NumPad.axaml index bc6c8e6..e8148cb 100644 --- a/src/Ursa.Themes.Semi/Controls/NumPad.axaml +++ b/src/Ursa.Themes.Semi/Controls/NumPad.axaml @@ -4,7 +4,7 @@ xmlns:u="https://irihi.tech/ursa"> - + @@ -18,22 +18,26 @@ - - - + + + - + @@ -84,7 +88,7 @@ NumContent="9" NumKey="NumPad9"> - + - + + NumContent="Enter" + NumKey="Enter" /> + NumKey="Decimal" /> diff --git a/src/Ursa/Controls/IPv4Box.cs b/src/Ursa/Controls/IPv4Box.cs index 889cdf3..0a232f3 100644 --- a/src/Ursa/Controls/IPv4Box.cs +++ b/src/Ursa/Controls/IPv4Box.cs @@ -136,7 +136,7 @@ public class IPv4Box: TemplatedControl if (_currentActivePresenter is null) return; var keymap = TopLevel.GetTopLevel(this)?.PlatformSettings?.HotkeyConfiguration; bool Match(List gestures) => gestures.Any(g => g.Matches(e)); - if (e.Key == Key.Enter) + if (e.Key is Key.Enter or Key.Return) { ParseBytes(ShowLeadingZero); SetIPAddressInternal(); @@ -170,25 +170,6 @@ public class IPv4Box: TemplatedControl _currentActivePresenter?.ShowCaret(); e.Handled = true; } - else if (e.Key == Key.OemPeriod || e.Key == Key.Decimal) - { - if (string.IsNullOrEmpty(_currentActivePresenter.Text)) - { - base.OnKeyDown(e); - return; - } - _currentActivePresenter?.HideCaret(); - _currentActivePresenter.ClearSelection(); - if (Equals(_currentActivePresenter, _fourthText)) - { - base.OnKeyDown(e); - return; - } - MoveToNextPresenter(_currentActivePresenter, false); - _currentActivePresenter?.ShowCaret(); - _currentActivePresenter.MoveCaretToStart(); - e.Handled = true; - } else if (e.Key == Key.Back) { DeleteImplementation(_currentActivePresenter); @@ -212,6 +193,16 @@ public class IPv4Box: TemplatedControl if (e.Handled) return; string? s = e.Text; if (string.IsNullOrEmpty(s)) return; + if (s == ".") + { + _currentActivePresenter?.HideCaret(); + _currentActivePresenter.ClearSelection(); + MoveToNextPresenter(_currentActivePresenter, false); + _currentActivePresenter?.ShowCaret(); + _currentActivePresenter.MoveCaretToStart(); + e.Handled = false; + return; + } if (!char.IsNumber(s![0])) return; if (_currentActivePresenter != null) {