Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 8, 2024
1 parent f76b916 commit 7f065f2
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/x-data-grid/src/utils/keyboardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,24 @@ export const isHideMenuKey = (key: React.KeyboardEvent['key']) => key === 'Tab'
// In theory, on macOS, ctrl + v doesn't trigger a paste, so the function should return false.
// However, maybe it's overkill to fix, so let's be lazy.
export function isPasteShortcut(event: React.KeyboardEvent) {
if (
return (
(event.ctrlKey || event.metaKey) &&
event.code === 'KeyV' &&
// We can't use event.code === 'KeyV' as event.code assumes a QWERTY keyboard layout,
// for example, it would be another letter on a Dvorak physical keyboard.
// We can't use event.key === 'v' as event.key is not stable with key modifiers and keyboard layouts,
// for example, it would be ה on a Hebrew keyboard layout.
String.fromCharCode(event.keyCode) === 'V' &&
!event.shiftKey &&
!event.altKey
) {
return true;
}
return false;
);
}

/**
* Checks if the keyboard event corresponds to the copy shortcut (CTRL+C or CMD+C) across different localization keyboards.
*
* @param {KeyboardEvent} event - The keyboard event to check.
* @returns {boolean} - Returns true if the event is a copy shortcut, otherwise false.
*/
// Checks if the keyboard event corresponds to the copy shortcut (CTRL+C or CMD+C) across different localization keyboards.
export function isCopyShortcut(event: KeyboardEvent): boolean {
return (
(event.ctrlKey || event.metaKey) && event.code === 'KeyC' && !event.shiftKey && !event.altKey
(event.ctrlKey || event.metaKey) &&
String.fromCharCode(event.keyCode) === 'C' &&
!event.shiftKey &&
!event.altKey
);
}

0 comments on commit 7f065f2

Please sign in to comment.