Files
upstream-mirror 1d2bfcac0c
Some checks failed
Prosody Plugin Tests / test (push) Failing after 10m11s
Close stale issues and PRs / stale (push) Failing after 1s
snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
2026-09-15 15:56:32 +05:00

98 lines
2.7 KiB
TypeScript

import PersistenceRegistry from '../base/redux/PersistenceRegistry';
import ReducerRegistry from '../base/redux/ReducerRegistry';
import {
DISABLE_KEYBOARD_SHORTCUTS,
ENABLE_KEYBOARD_SHORTCUTS,
REGISTER_KEYBOARD_SHORTCUT,
SET_CTRL_ALT_REACTION_SHORTCUTS_ENABLED,
UNREGISTER_KEYBOARD_SHORTCUT
} from './actionTypes';
import { IKeyboardShortcutsState } from './types';
/**
* The redux subtree of this feature.
*/
const STORE_NAME = 'features/keyboard-shortcuts';
const defaultState = {
ctrlAltReactionShortcutsEnabled: true,
enabled: true,
shortcuts: new Map(),
shortcutsHelp: new Map()
};
PersistenceRegistry.register(STORE_NAME, {
ctrlAltReactionShortcutsEnabled: true,
enabled: true
});
ReducerRegistry.register<IKeyboardShortcutsState>(STORE_NAME,
(state = defaultState, action): IKeyboardShortcutsState => {
switch (action.type) {
case ENABLE_KEYBOARD_SHORTCUTS:
return {
...state,
enabled: true
};
case DISABLE_KEYBOARD_SHORTCUTS:
return {
...state,
enabled: false
};
case SET_CTRL_ALT_REACTION_SHORTCUTS_ENABLED:
return {
...state,
ctrlAltReactionShortcutsEnabled: action.enabled
};
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}`;
}
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
};
}
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 shortcuts = new Map(state.shortcuts);
shortcuts.delete(shortcutKey);
const shortcutsHelp = new Map(state.shortcutsHelp);
shortcutsHelp.delete(shortcutKey);
return {
...state,
shortcuts,
shortcutsHelp
};
}
}
return state;
});