Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions SkEditor/Views/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Threading;
using AvaloniaEdit;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls;
using FluentAvalonia.UI.Windowing;
Expand All @@ -25,6 +26,7 @@ public partial class MainWindow : AppWindow
private readonly SplashScreen? _splashScreen;
private bool _isFullyLoaded;
private WindowState _preFullScreenState;
private bool _layoutSwitchDetected;

public MainWindow(SplashScreen? splashScreen = null)
{
Expand Down Expand Up @@ -103,6 +105,52 @@ private void AddEvents()
};

AddHandler(DragDrop.DropEvent, FileHandler.FileDropAction);

AddHandler(KeyDownEvent, (_, e) =>
{
if (e.Key is Key.LeftAlt or Key.RightAlt && e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
_layoutSwitchDetected = true;
}
else if (e.Key is Key.LeftShift or Key.RightShift && e.KeyModifiers.HasFlag(KeyModifiers.Alt))
{
_layoutSwitchDetected = true;
}
else if (e.Key is Key.LeftShift or Key.RightShift && e.KeyModifiers.HasFlag(KeyModifiers.Control))
{
_layoutSwitchDetected = true;
}
else if (e.Key is Key.LeftCtrl or Key.RightCtrl && e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
_layoutSwitchDetected = true;
}
}, RoutingStrategies.Tunnel);

AddHandler(KeyUpEvent, (_, e) =>
{
bool isLayoutSwitchKey = e.Key is Key.LeftAlt or Key.RightAlt
or Key.LeftShift or Key.RightShift
or Key.LeftCtrl or Key.RightCtrl;

if (!isLayoutSwitchKey || !_layoutSwitchDetected)
{
return;
}

_layoutSwitchDetected = false;

OpenedFile? currentFile = SkEditorAPI.Files.GetCurrentOpenedFile();
if (currentFile?.Editor?.TextArea is not { } textArea)
{
return;
}

if (textArea.IsFocused)
{
e.Handled = true;
Dispatcher.UIThread.Post(() => textArea.Focus());
}
}, RoutingStrategies.Tunnel);
}

public void ReloadUiOfAddons()
Expand Down