Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distraction free mode: Fix keyboard shortcut not working #47900

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions packages/keycodes/src/index.js
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment was taken from the source code of chromium

IntlRo: '\\',
IntlYen: '\\',
};

const modsDiff = mods.filter(
( mod ) => ! eventMods.includes( mod )
@@ -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.