Skip to content

Commit

Permalink
[core] Fix shortcuts when Caps Lock enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 18, 2024
1 parent 0cd3b4f commit 00329e3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,13 @@ function defaultPasteResolver({
});
}

const isPasteShortcut = (event: React.KeyboardEvent) => {
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'v') {
if (event.shiftKey || event.altKey) {
return false;
}
function isPasteShortcut(event: React.KeyboardEvent) {
if (
(event.ctrlKey || event.metaKey) &&
event.key.toLowerCase() === 'v' &&
!event.shiftKey &&
!event.altKey
) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ export const useGridClipboard = (

const handleCopy = React.useCallback(
(event: KeyboardEvent) => {
if (!((event.ctrlKey || event.metaKey) && event.key === 'c')) {
if (
!(
(event.ctrlKey || event.metaKey) &&
event.key.toLowerCase() === 'c' &&
!event.shiftKey &&
!event.altKey
)
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ export const useGridCellEditing = (
}
if (isPrintableKey(event)) {
reason = GridCellEditStartReasons.printableKeyDown;
} else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
} else if (
(event.ctrlKey || event.metaKey) &&
event.key.toLowerCase() === 'v' &&
!event.shiftKey &&
!event.altKey
) {
reason = GridCellEditStartReasons.pasteKeyDown;
} else if (event.key === 'Enter') {
reason = GridCellEditStartReasons.enterKeyDown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ export const useGridRowEditing = (

if (isPrintableKey(event)) {
reason = GridRowEditStartReasons.printableKeyDown;
} else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
} else if (
(event.ctrlKey || event.metaKey) &&
event.key.toLowerCase() === 'v' &&
!event.shiftKey &&
!event.altKey
) {
reason = GridRowEditStartReasons.printableKeyDown;
} else if (event.key === 'Enter') {
reason = GridRowEditStartReasons.enterKeyDown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ export const useField = <
// eslint-disable-next-line default-case
switch (true) {
// Select all
case event.key === 'a' && (event.ctrlKey || event.metaKey): {
case (event.ctrlKey || event.metaKey) &&
event.key.toLowerCase() === 'a' &&
!event.shiftKey &&
!event.altKey: {
// prevent default to make sure that the next line "select all" while updating
// the internal state at the same time.
event.preventDefault();
Expand Down

0 comments on commit 00329e3

Please sign in to comment.