Skip to content

Commit

Permalink
Distraction free mode: Fix keyboard shortcut not working (#47900)
Browse files Browse the repository at this point in the history
* Distraction free mode: Fix keyboard shortcut not working on Windows

* Include mac
  • Loading branch information
t-hamano authored Feb 13, 2023
1 parent 1eea892 commit f1bc31a
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions packages/keycodes/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ export const isKeyboardEvent = mapValues(
) => {
const mods = getModifiers( _isApple );
const eventMods = getEventModifiers( event );
/** @type {Record<string,string>} */
const replacementWithShiftKeyMap = {
Comma: ',',
Backslash: '\\',
// Windows returns `\` for both IntlRo and IntlYen.
IntlRo: '\\',
IntlYen: '\\',
};

const modsDiff = mods.filter(
( mod ) => ! eventMods.includes( mod )
Expand All @@ -412,16 +420,17 @@ export const isKeyboardEvent = mapValues(
key = String.fromCharCode( event.keyCode ).toLowerCase();
}

// Replace some characters to match the key indicated
// by the shortcut on Windows.
if ( ! _isApple() ) {
if (
event.shiftKey &&
character.length === 1 &&
event.code === 'Comma'
) {
key = ',';
}
// `event.key` returns the value of the key pressed, taking into the state of
// modifier keys such as `Shift`. If the shift key is pressed, a different
// value may be returned depending on the keyboard layout. It is necessary to
// convert to the physical key value that don't take into account keyboard
// layout or modifier key state.
if (
event.shiftKey &&
character.length === 1 &&
replacementWithShiftKeyMap[ event.code ]
) {
key = replacementWithShiftKeyMap[ event.code ];
}

// For backwards compatibility.
Expand Down

1 comment on commit f1bc31a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in f1bc31a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4161883966
📝 Reported issues:

Please sign in to comment.