Adds keyboard shortcut to open context menu on messages
This commit is contained in:
parent
498205b964
commit
7247c2d674
5 changed files with 114 additions and 14 deletions
|
@ -234,6 +234,39 @@ export function useToggleReactionPicker(
|
|||
);
|
||||
}
|
||||
|
||||
export function useOpenContextMenu(
|
||||
openContextMenu: () => unknown
|
||||
): KeyboardShortcutHandlerType {
|
||||
const hasOverlay = useHasAnyOverlay();
|
||||
|
||||
return useCallback(
|
||||
ev => {
|
||||
if (hasOverlay) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { shiftKey } = ev;
|
||||
const key = KeyboardLayout.lookup(ev);
|
||||
|
||||
const isMacOS = get(window, 'platform') === 'darwin';
|
||||
|
||||
if (
|
||||
(!isMacOS && shiftKey && key === 'F10') ||
|
||||
(isMacOS && isCmdOrCtrl(ev) && key === 'F12')
|
||||
) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
openContextMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
[hasOverlay, openContextMenu]
|
||||
);
|
||||
}
|
||||
|
||||
export function useEditLastMessageSent(
|
||||
maybeEditMessage: () => boolean
|
||||
): KeyboardShortcutHandlerType {
|
||||
|
@ -277,3 +310,23 @@ export function useKeyboardShortcuts(
|
|||
};
|
||||
}, [eventHandlers]);
|
||||
}
|
||||
|
||||
export function useKeyboardShortcutsConditionally(
|
||||
condition: boolean,
|
||||
...eventHandlers: Array<KeyboardShortcutHandlerType>
|
||||
): void {
|
||||
useEffect(() => {
|
||||
if (!condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
function handleKeydown(ev: KeyboardEvent): void {
|
||||
eventHandlers.some(eventHandler => eventHandler(ev));
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', handleKeydown);
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeydown);
|
||||
};
|
||||
}, [condition, eventHandlers]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue