snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
This commit is contained in:
97
react/features/keyboard-shortcuts/reducer.ts
Normal file
97
react/features/keyboard-shortcuts/reducer.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
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;
|
||||
});
|
||||
Reference in New Issue
Block a user