Skip to content

Commit

Permalink
Merge pull request #7321 from ltetak/datagrid_osx_hotkeys
Browse files Browse the repository at this point in the history
[macOS] DataGrid - handle OSX key modifiers (ctrl vs cmd)
  • Loading branch information
maxkatz6 authored and danwalmsley committed Jan 24, 2022
1 parent c763ee2 commit 7b6ccef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Avalonia.Controls.DataGrid/DataGridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ public static DataGridColumn GetColumnContainingElement(IControl element)
public void ClearSort()
{
//InvokeProcessSort is already validating if sorting is possible
_headerCell?.InvokeProcessSort(Input.KeyModifiers.Control);
_headerCell?.InvokeProcessSort(KeyboardHelper.GetPlatformCtrlOrCmdKeyModifier());
}

/// <summary>
Expand Down
21 changes: 14 additions & 7 deletions src/Avalonia.Controls.DataGrid/Utils/KeyboardHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
// All other rights reserved.

using Avalonia.Input;
using Avalonia.Input.Platform;

namespace Avalonia.Controls.Utils
{
internal static class KeyboardHelper
{
public static void GetMetaKeyState(KeyModifiers modifiers, out bool ctrl, out bool shift)
public static void GetMetaKeyState(KeyModifiers modifiers, out bool ctrlOrCmd, out bool shift)
{
ctrl = (modifiers & KeyModifiers.Control) == KeyModifiers.Control;
shift = (modifiers & KeyModifiers.Shift) == KeyModifiers.Shift;
ctrlOrCmd = modifiers.HasFlag(GetPlatformCtrlOrCmdKeyModifier());
shift = modifiers.HasFlag(KeyModifiers.Shift);
}

public static void GetMetaKeyState(KeyModifiers modifiers, out bool ctrl, out bool shift, out bool alt)
public static void GetMetaKeyState(KeyModifiers modifiers, out bool ctrlOrCmd, out bool shift, out bool alt)
{
ctrl = (modifiers & KeyModifiers.Control) == KeyModifiers.Control;
shift = (modifiers & KeyModifiers.Shift) == KeyModifiers.Shift;
alt = (modifiers & KeyModifiers.Alt) == KeyModifiers.Alt;
ctrlOrCmd = modifiers.HasFlag(GetPlatformCtrlOrCmdKeyModifier());
shift = modifiers.HasFlag(KeyModifiers.Shift);
alt = modifiers.HasFlag(KeyModifiers.Alt);
}

public static KeyModifiers GetPlatformCtrlOrCmdKeyModifier()
{
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>();
return keymap?.CommandModifiers ?? KeyModifiers.Control;
}
}
}

0 comments on commit 7b6ccef

Please sign in to comment.