Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(keyboard-shortcuts): clean up stale keyboard shortcut help entries (#18053)

Puneet Yadav9a4d3aa72b95
diff --git a/react/features/keyboard-shortcuts/actions.ts b/react/features/keyboard-shortcuts/actions.ts
index 5e5db191b3..ffa9572ccd 100644
--- a/react/features/keyboard-shortcuts/actions.ts
+++ b/react/features/keyboard-shortcuts/actions.ts
@@ -133,10 +133,8 @@ function initGlobalKeyboardShortcuts(dispatch: IStore['dispatch']) {
for (let num = 1; num < 10; num++) {
dispatch(registerShortcut({
character: `${num}`,
-
- // only show help hint for the first shortcut
- helpCharacter: num === 1 ? '1-9' : undefined,
- helpDescription: num === 1 ? 'keyboardShortcuts.focusRemote' : undefined,
+ helpCharacter: '1-9',
+ helpDescription: 'keyboardShortcuts.focusRemote',
handler: () => {
dispatch(clickOnVideo(num));
}
diff --git a/react/features/keyboard-shortcuts/functions.ts b/react/features/keyboard-shortcuts/functions.ts
index 2ac29aad27..e9110877c9 100644
--- a/react/features/keyboard-shortcuts/functions.ts
+++ b/react/features/keyboard-shortcuts/functions.ts
@@ -42,5 +42,14 @@ export function getKeyboardShortcuts(state: IReduxState) {
* @returns {Map} - The keyboard shortcuts help descriptions.
*/
export function getKeyboardShortcutsHelpDescriptions(state: IReduxState) {
- return state['features/keyboard-shortcuts'].shortcutsHelp;
+ const shortcuts = getKeyboardShortcuts(state);
+ const shortcutsHelp = new Map<string, string>();
+
+ for (const [ key, shortcut ] of shortcuts) {
+ if (shortcut.helpDescription) {
+ shortcutsHelp.set(shortcut.helpCharacter ?? key, shortcut.helpDescription);
+ }
+ }
+
+ return shortcutsHelp;
}
diff --git a/react/features/keyboard-shortcuts/reducer.ts b/react/features/keyboard-shortcuts/reducer.ts
index 02e92587bd..ae42d74bf1 100644
--- a/react/features/keyboard-shortcuts/reducer.ts
+++ b/react/features/keyboard-shortcuts/reducer.ts
@@ -9,6 +9,7 @@ import {
UNREGISTER_KEYBOARD_SHORTCUT
} from './actionTypes';
import { IKeyboardShortcutsState } from './types';
+import { getShortcutKey } from './utils';
/**
* The redux subtree of this feature.
@@ -18,8 +19,7 @@ const STORE_NAME = 'features/keyboard-shortcuts';
const defaultState = {
ctrlAltReactionShortcutsEnabled: true,
enabled: true,
- shortcuts: new Map(),
- shortcutsHelp: new Map()
+ shortcuts: new Map()
};
PersistenceRegistry.register(STORE_NAME, {
@@ -47,48 +47,23 @@ ReducerRegistry.register<IKeyboardShortcutsState>(STORE_NAME,
};
case REGISTER_KEYBOARD_SHORTCUT: {
const { alt, character, ctrl } = action.shortcut;
- let shortcutKey = character;
-
- if (ctrl && alt) {
- shortcutKey = `-:${character}`;
- } else if (alt) {
- shortcutKey = `:${character}`;
- } else if (ctrl) {
- shortcutKey = `-${character}`;
- }
+ const shortcutKey = getShortcutKey(character, alt, ctrl);
return {
...state,
shortcuts: new Map(state.shortcuts)
- .set(shortcutKey, action.shortcut),
- shortcutsHelp: action.shortcut.helpDescription
- ? new Map(state.shortcutsHelp)
- .set(action.shortcut.helpCharacter ?? shortcutKey, action.shortcut.helpDescription)
- : state.shortcutsHelp
+ .set(shortcutKey, action.shortcut)
};
}
case UNREGISTER_KEYBOARD_SHORTCUT: {
- let shortcutKey = action.character;
-
- if (action.ctrl && action.alt) {
- shortcutKey = `-:${action.character}`;
- } else if (action.alt) {
- shortcutKey = `:${action.character}`;
- } else if (action.ctrl) {
- shortcutKey = `-${action.character}`;
- }
+ const shortcutKey = getShortcutKey(action.character, action.alt, action.ctrl);
const shortcuts = new Map(state.shortcuts);
shortcuts.delete(shortcutKey);
- const shortcutsHelp = new Map(state.shortcutsHelp);
-
- shortcutsHelp.delete(shortcutKey);
-
return {
...state,
- shortcuts,
- shortcutsHelp
+ shortcuts
};
}
}
diff --git a/react/features/keyboard-shortcuts/types.ts b/react/features/keyboard-shortcuts/types.ts
index 086a17dd97..efb6793d12 100644
--- a/react/features/keyboard-shortcuts/types.ts
+++ b/react/features/keyboard-shortcuts/types.ts
@@ -23,5 +23,4 @@ export interface IKeyboardShortcutsState {
ctrlAltReactionShortcutsEnabled: boolean;
enabled: boolean;
shortcuts: Map<string, IKeyboardShortcut>;
- shortcutsHelp: Map<string, string>;
}
diff --git a/react/features/keyboard-shortcuts/utils.ts b/react/features/keyboard-shortcuts/utils.ts
index a8a9408bff..9d0b8fa04e 100644
--- a/react/features/keyboard-shortcuts/utils.ts
+++ b/react/features/keyboard-shortcuts/utils.ts
@@ -25,6 +25,18 @@ const _elementsBlacklist = [
export const getPriorityFocusedElement = (): HTMLElement | null =>
document.querySelector(`:focus:is(${_elementsBlacklist.join(',')})`);
+export const getShortcutKey = (character: string, alt?: boolean, ctrl?: boolean): string => {
+ if (ctrl && alt) {
+ return `-:${character}`;
+ } else if (alt) {
+ return `:${character}`;
+ } else if (ctrl) {
+ return `-${character}`;
+ }
+
+ return character;
+};
+
/**
* Returns the keyboard key from a KeyboardEvent.
*
@@ -41,12 +53,8 @@ export const getKeyboardKey = (e: KeyboardEvent): string => {
const replacedKey = code.replace('Key', '');
- if (ctrlKey && altKey) {
- return `-:${replacedKey}`;
- }
-
if (altKey) {
- return `:${replacedKey}`;
+ return getShortcutKey(replacedKey, altKey, ctrlKey);
}
// If e.key is a string, then it is assumed it already plainly states
@@ -56,7 +64,7 @@ export const getKeyboardKey = (e: KeyboardEvent): string => {
// further analyzed by jitsi to a key using e.which.
if (typeof key === 'string' && key !== 'Unidentified') {
if (ctrlKey) {
- return `-${key}`;
+ return getShortcutKey(key, false, ctrlKey);
}
if (code.startsWith('Key')) {