Skip to content

Commit

Permalink
Fixed an issue with key detection in Japanese IME environments, causi…
Browse files Browse the repository at this point in the history
…ng issues with the MouseGesture
  • Loading branch information
miroiu committed Jan 23, 2025
1 parent bc01626 commit 41e413a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
> - Bugfixes:
> - Fixed an issue where connections would not gain focus when selected, which could prevent editor keybindings from functioning in certain scenarios
> - Resolved an issue where selecting a node did not deselect connections and vice versa
> - Fixed a bug preventing ItemContainers from being dragged when the mouse could not be captured
> - Fixed a bug preventing ItemContainers from being selected when the mouse could not be captured
> - Fixed an issue with key detection in Japanese IME environments, causing issues with the MouseGesture
#### **Version 7.0.0**

Expand Down
8 changes: 6 additions & 2 deletions Nodify/Containers/States/Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ protected override void OnMouseDown(MouseButtonEventArgs e)
EditorGestures.ItemContainerGestures gestures = EditorGestures.Mappings.ItemContainer;
if (gestures.Drag.Matches(e.Source, e))
{
_isDragging = Element.IsDraggable;
// Dragging requires mouse capture
_isDragging = Element.IsDraggable && CanCaptureMouse();
}

if (gestures.Selection.Select.Matches(e.Source, e))
Expand Down Expand Up @@ -110,13 +111,16 @@ protected override void OnMouseUp(MouseButtonEventArgs e)
private void CaptureMouseSafe()
{
// Avoid stealing mouse capture from other elements
if (Mouse.Captured == null || Element.IsMouseCaptured)
if (CanCaptureMouse())
{
Element.Focus();
Element.CaptureMouse();
}
}

private bool CanCaptureMouse()
=> Mouse.Captured == null || Element.IsMouseCaptured;

private static SelectionType GetSelectionTypeForDragging(SelectionType? selectionType)
{
// Always select the container when dragging
Expand Down
53 changes: 31 additions & 22 deletions Nodify/Interactivity/Gestures/MouseGesture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,40 @@ private bool MatchesKeyboard()
return !IsAnyKeyPressed();
}

return Keyboard.GetKeyStates(Key).HasFlag(KeyStates.Down);
return Keyboard.IsKeyDown(Key);
}

private static readonly Key[] _allKeys = GetValidKeys();

private static Key[] GetValidKeys()
private static readonly Key[] _allKeys = new[]
{
var excludedKeys = new[]
{
Key.LeftCtrl, Key.RightCtrl,
Key.LeftShift, Key.RightShift,
Key.LeftAlt, Key.RightAlt,
Key.LWin, Key.RWin,
Key.None
};

#if NET5_0_OR_GREATER
return Enum.GetValues<Key>()
#else
return Enum.GetValues(typeof(Key))
.Cast<Key>()
#endif
.Where(key => !excludedKeys.Contains(key))
.ToArray();
}
// Alphanumeric
Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, Key.J,
Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, Key.T,
Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z,
Key.D0, Key.D1, Key.D2, Key.D3, Key.D4, Key.D5, Key.D6, Key.D7, Key.D8, Key.D9,

// Punctuation and symbols
Key.Oem3, Key.OemMinus, Key.OemPlus, Key.OemOpenBrackets, Key.OemCloseBrackets,
Key.Oem5, Key.Oem1, Key.OemQuotes, Key.OemComma, Key.OemPeriod, Key.Oem2,

// Function keys
Key.F1, Key.F2, Key.F3, Key.F4, Key.F5, Key.F6, Key.F7, Key.F8,
Key.F9, Key.F10, Key.F11, Key.F12,

// Navigation
Key.Left, Key.Right, Key.Up, Key.Down,
Key.PageUp, Key.PageDown, Key.Home, Key.End,

// Editing
Key.Back, Key.Delete, Key.Insert,

// Special
Key.Space, Key.Return, Key.Escape, Key.Tab,

// Numeric keypad
Key.NumPad0, Key.NumPad1, Key.NumPad2, Key.NumPad3, Key.NumPad4,
Key.NumPad5, Key.NumPad6, Key.NumPad7, Key.NumPad8, Key.NumPad9,
Key.Multiply, Key.Add, Key.Subtract, Key.Divide, Key.Decimal
};

/// <summary>
/// Determines whether any key (excluding modifiers) is currently pressed.
Expand Down

0 comments on commit 41e413a

Please sign in to comment.