diff --git a/lib/src/manager/shortcut/pluto_grid_shortcut.dart b/lib/src/manager/shortcut/pluto_grid_shortcut.dart index e926e34a2..c5d660699 100644 --- a/lib/src/manager/shortcut/pluto_grid_shortcut.dart +++ b/lib/src/manager/shortcut/pluto_grid_shortcut.dart @@ -2,6 +2,19 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:pluto_grid_plus/pluto_grid_plus.dart'; +// Create a custom wrapper that filters out NumLock. +// This will enable the arrow keys and shortcuts to work correctly on Linux too. +class FilteredHardwareKeyboard extends HardwareKeyboard { + final Set filteredKeys; + + FilteredHardwareKeyboard(this.filteredKeys); + + // Override the HardwareKeyboard logicalKeysPressed to get only the + // filtered keys without NumLock. + @override + Set get logicalKeysPressed => filteredKeys; +} + /// Class for setting shortcut actions. /// /// Defaults to [PlutoGridShortcut.defaultActions] if not passing [actions]. @@ -29,8 +42,17 @@ class PlutoGridShortcut { required PlutoGridStateManager stateManager, required HardwareKeyboard state, }) { + // Remove NumLock before checking shortcuts. This will enable the arrow + // keys and shortcuts to work correctly on Linux too. + final Set filteredKeys = state.logicalKeysPressed + .where((key) => key != LogicalKeyboardKey.numLock) + .toSet(); + // Create a wrapper around the HardwareKeyboard instance with filtered keys. + final FilteredHardwareKeyboard fakeState = + FilteredHardwareKeyboard(filteredKeys); + for (final action in actions.entries) { - if (action.key.accepts(keyEvent.event, state)) { + if (action.key.accepts(keyEvent.event, fakeState)) { action.value.execute(keyEvent: keyEvent, stateManager: stateManager); return true; } diff --git a/lib/src/ui/columns/pluto_column_title.dart b/lib/src/ui/columns/pluto_column_title.dart index 79f75573b..8c5ef5ab7 100644 --- a/lib/src/ui/columns/pluto_column_title.dart +++ b/lib/src/ui/columns/pluto_column_title.dart @@ -152,7 +152,15 @@ class PlutoColumnTitleState extends PlutoStateWithChange { ), iconSize: style.iconSize, mouseCursor: contextMenuCursor, - onPressed: null, + hoverColor: Colors.transparent, + splashColor: Colors.transparent, + highlightColor: Colors.transparent, + onPressed: () { + if (mounted && widget.column.enableSorting && + !widget.column.enableContextMenu) { + stateManager.toggleSortColumn(widget.column); + } + }, ), ), );