Browse Source

Adjusted shortcuts for macos

Krzysztof Krysiński 6 months ago
parent
commit
7bdfddfee0
1 changed files with 26 additions and 0 deletions
  1. 26 0
      src/PixiEditor/Views/Overlays/TextOverlay/TextOverlay.cs

+ 26 - 0
src/PixiEditor/Views/Overlays/TextOverlay/TextOverlay.cs

@@ -189,10 +189,13 @@ internal class TextOverlay : Overlay
             { new KeyCombination(Key.End, KeyModifiers.Shift), () => GoToEndOfLine(false) },
         };
 
+        AdjustShortcutsForOS();
+
         selectionPaint = new Paint()
         {
             Color = ThemeResources.SelectionFillColor.WithAlpha(255), Style = PaintStyle.Fill
         };
+
         opacityPaint = new Paint() { Color = Colors.White.WithAlpha(ThemeResources.SelectionFillColor.A) };
     }
 
@@ -630,6 +633,29 @@ internal class TextOverlay : Overlay
         glyphWidths = richText.GetGlyphWidths(Font);
     }
 
+    private void AdjustShortcutsForOS()
+    {
+        if (IOperatingSystem.Current.IsMacOs)
+        {
+            Dictionary<KeyCombination, Action> newShortcuts = new();
+            foreach (var shortcut in shortcuts)
+            {
+                if (shortcut.Key.Modifiers.HasFlag(KeyModifiers.Control))
+                {
+                    KeyModifiers newModifiers = shortcut.Key.Modifiers & ~KeyModifiers.Control;
+                    newModifiers |= KeyModifiers.Meta;
+                    newShortcuts.Add(new KeyCombination(shortcut.Key.Key, newModifiers), shortcut.Value);
+                }
+                else
+                {
+                    newShortcuts.Add(shortcut.Key, shortcut.Value);
+                }
+            }
+
+            shortcuts = newShortcuts;
+        }
+    }
+
     private static void IsVisibleChanged(AvaloniaPropertyChangedEventArgs<bool> args)
     {
         TextOverlay sender = args.Sender as TextOverlay;