Fix shortcuts removed by user still displayed, even if not working (#3618)

This commit is contained in:
Nilay Majorwar
2022-02-14 19:10:09 +05:30
committed by GitHub
parent ca19076b01
commit 942a3117f9

View File

@@ -18,6 +18,19 @@ import commandsList, {
commandAreas,
} from '../CommandPalette/CommandsList';
/**
* Get shortcut string to be displayed after patching the default
* shortcut with user-defined shortcut, if any.
*/
const getPatchedShortcutString = (
defaultShortcut: string,
userShortcut?: string
) => {
// User shortcut can be empty string when user has removed a shortcut,
// so we check userShortcut against null/undefined.
return userShortcut == null ? defaultShortcut : userShortcut;
};
/**
* Sorts all commands into an object keyed by area name, and also creates a
* reverse mapping from shortcut string to list of commands with that shortcut.
@@ -38,7 +51,10 @@ const sortCommandsIntoAreasAndGetReverseMap = (
// Add to shortcut-command mapping
const userShortcut = userShortcutMap[name];
const defaultShortcut = defaultShortcuts[name] || '';
const shortcutString = userShortcut || defaultShortcut;
const shortcutString = getPatchedShortcutString(
defaultShortcut,
userShortcut
);
if (shortcutString === '') return;
shortcutStringToCommands[shortcutString] = (
shortcutStringToCommands[shortcutString] || []
@@ -110,7 +126,10 @@ const ShortcutsList = (props: Props) => {
// Get default and user-set shortcuts
const userShortcut = props.userShortcutMap[commandName];
const defaultShortcut = defaultShortcuts[commandName] || '';
const shortcutString = userShortcut || defaultShortcut;
const shortcutString = getPatchedShortcutString(
defaultShortcut,
userShortcut
);
const shortcutDisplayName = getShortcutDisplayName(
shortcutString
);
@@ -124,7 +143,7 @@ const ShortcutsList = (props: Props) => {
key={commandName}
shortcutString={shortcutDisplayName}
commandName={commandName}
isDefault={!userShortcut}
isDefault={shortcutString === defaultShortcut}
isClashing={hasClash}
onEditShortcut={() => setEditedShortcut(commandName)}
onResetShortcut={() => resetShortcut(commandName)}