fix: fix IPV4Box key handling in DataGrid. Add a SampleBox project for extra testing. Upgrade to released version.

This commit is contained in:
rabbitism
2024-07-27 22:00:39 +08:00
parent f073ce76c2
commit 57b1dd808a
17 changed files with 295 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<AvaloniaVersion>11.1.0-rc2</AvaloniaVersion>
<AvaloniaVersion>11.1.1</AvaloniaVersion>
</PropertyGroup>
</Project>

View File

@@ -42,6 +42,7 @@
<Setter Property="u:IPv4Box.SelectionForegroundBrush" Value="{DynamicResource IPv4BoxSelectionForeground}" />
<Setter Property="u:IPv4Box.CaretBrush" Value="{DynamicResource IPv4BoxCaretBrush}" />
<Setter Property="u:IPv4Box.ContextFlyout" Value="{DynamicResource IPv4BoxMenuFlyout}" />
<Setter Property="FocusAdorner" Value="{x:Null}"></Setter>
<Setter Property="u:IPv4Box.Template">
<ControlTemplate TargetType="u:IPv4Box">
<Border

View File

@@ -133,7 +133,11 @@ public class IPv4Box: TemplatedControl
protected override void OnKeyDown(KeyEventArgs e)
{
if (_currentActivePresenter is null) return;
if (_currentActivePresenter is null)
{
_currentActivePresenter = _presenters[0];
}
var keymap = TopLevel.GetTopLevel(this)?.PlatformSettings?.HotkeyConfiguration;
bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e));
if (e.Key is Key.Enter or Key.Return)
@@ -141,25 +145,36 @@ public class IPv4Box: TemplatedControl
ParseBytes(ShowLeadingZero);
SetIPAddressInternal();
base.OnKeyDown(e);
e.Handled = true;
return;
}
if (keymap is not null && Match(keymap.SelectAll))
{
_currentActivePresenter.SelectionStart = 0;
_currentActivePresenter.SelectionEnd = _currentActivePresenter.Text?.Length ?? 0;
e.Handled = true;
return;
}
else if (keymap is not null && Match(keymap.Copy))
if (keymap is not null && Match(keymap.Copy))
{
Copy();
e.Handled = true;
return;
}
else if (keymap is not null && Match(keymap.Paste))
if (keymap is not null && Match(keymap.Paste))
{
Paste();
e.Handled = true;
return;
}
else if (keymap is not null && Match(keymap.Cut))
if (keymap is not null && Match(keymap.Cut))
{
Cut();
e.Handled = true;
return;
}
if (e.Key == Key.Tab)
{
@@ -173,23 +188,30 @@ public class IPv4Box: TemplatedControl
MoveToNextPresenter(_currentActivePresenter, true);
_currentActivePresenter?.ShowCaret();
e.Handled = true;
return;
}
else if (e.Key == Key.Back)
if (e.Key == Key.Back)
{
DeleteImplementation(_currentActivePresenter);
e.Handled = true;
return;
}
else if (e.Key == Key.Right )
if (e.Key == Key.Right )
{
OnPressRightKey();
e.Handled = true;
return;
}
else if (e.Key == Key.Left)
if (e.Key == Key.Left)
{
OnPressLeftKey();
e.Handled = true;
return;
}
else
{
base.OnKeyDown(e);
}
base.OnKeyDown(e);
}
protected override void OnTextInput(TextInputEventArgs e)
@@ -201,9 +223,11 @@ public class IPv4Box: TemplatedControl
{
_currentActivePresenter?.HideCaret();
_currentActivePresenter.ClearSelection();
MoveToNextPresenter(_currentActivePresenter, false);
_currentActivePresenter?.ShowCaret();
_currentActivePresenter.MoveCaretToStart();
if (MoveToNextPresenter(_currentActivePresenter, false))
{
_currentActivePresenter?.ShowCaret();
_currentActivePresenter.MoveCaretToStart();
}
e.Handled = false;
return;
}
@@ -274,6 +298,7 @@ public class IPv4Box: TemplatedControl
}
}
base.OnPointerPressed(e);
e.Handled = true;
}
protected override void OnLostFocus(RoutedEventArgs e)