Handle cmd+shift+e keyboard shortcut
This commit is contained in:
parent
1109415dc1
commit
bc4f3dcd01
3 changed files with 41 additions and 0 deletions
|
@ -218,6 +218,7 @@ export class TimelineItem extends React.PureComponent<PropsType> {
|
||||||
<TimelineMessage
|
<TimelineMessage
|
||||||
{...this.props}
|
{...this.props}
|
||||||
{...item.data}
|
{...item.data}
|
||||||
|
isSelected={isSelected}
|
||||||
shouldCollapseAbove={shouldCollapseAbove}
|
shouldCollapseAbove={shouldCollapseAbove}
|
||||||
shouldCollapseBelow={shouldCollapseBelow}
|
shouldCollapseBelow={shouldCollapseBelow}
|
||||||
shouldHideMetadata={shouldHideMetadata}
|
shouldHideMetadata={shouldHideMetadata}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { noop } from 'lodash';
|
||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import type { Ref } from 'react';
|
import type { Ref } from 'react';
|
||||||
import { ContextMenu, ContextMenuTrigger, MenuItem } from 'react-contextmenu';
|
import { ContextMenu, ContextMenuTrigger, MenuItem } from 'react-contextmenu';
|
||||||
|
@ -25,6 +26,7 @@ import type {
|
||||||
} from './Message';
|
} from './Message';
|
||||||
import { doesMessageBodyOverflow } from './MessageBodyReadMore';
|
import { doesMessageBodyOverflow } from './MessageBodyReadMore';
|
||||||
import type { Props as ReactionPickerProps } from './ReactionPicker';
|
import type { Props as ReactionPickerProps } from './ReactionPicker';
|
||||||
|
import { useToggleReactionPicker } from '../../hooks/useKeyboardShortcuts';
|
||||||
|
|
||||||
export type PropsData = {
|
export type PropsData = {
|
||||||
canDownload: boolean;
|
canDownload: boolean;
|
||||||
|
@ -33,6 +35,7 @@ export type PropsData = {
|
||||||
canReact: boolean;
|
canReact: boolean;
|
||||||
canReply: boolean;
|
canReply: boolean;
|
||||||
selectedReaction?: string;
|
selectedReaction?: string;
|
||||||
|
isSelected?: boolean;
|
||||||
} & Omit<MessagePropsData, 'renderingContext' | 'menu'>;
|
} & Omit<MessagePropsData, 'renderingContext' | 'menu'>;
|
||||||
|
|
||||||
export type PropsActions = {
|
export type PropsActions = {
|
||||||
|
@ -86,6 +89,7 @@ export function TimelineMessage(props: Props): JSX.Element {
|
||||||
deleteMessageForEveryone,
|
deleteMessageForEveryone,
|
||||||
direction,
|
direction,
|
||||||
giftBadge,
|
giftBadge,
|
||||||
|
isSelected,
|
||||||
isSticker,
|
isSticker,
|
||||||
isTapToView,
|
isTapToView,
|
||||||
reactToMessage,
|
reactToMessage,
|
||||||
|
@ -233,6 +237,20 @@ export function TimelineMessage(props: Props): JSX.Element {
|
||||||
|
|
||||||
const handleReact = canReact ? () => toggleReactionPicker() : undefined;
|
const handleReact = canReact ? () => toggleReactionPicker() : undefined;
|
||||||
|
|
||||||
|
const toggleReactionPickerKeyboard = useToggleReactionPicker(
|
||||||
|
handleReact || noop
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSelected) {
|
||||||
|
document.addEventListener('keydown', toggleReactionPickerKeyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keydown', toggleReactionPickerKeyboard);
|
||||||
|
};
|
||||||
|
}, [isSelected, toggleReactionPickerKeyboard]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Message
|
<Message
|
||||||
|
|
|
@ -159,6 +159,28 @@ export function useAttachFileShortcut(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useToggleReactionPicker(
|
||||||
|
handleReact: () => unknown
|
||||||
|
): KeyboardShortcutHandlerType {
|
||||||
|
return useCallback(
|
||||||
|
ev => {
|
||||||
|
const { shiftKey } = ev;
|
||||||
|
const key = KeyboardLayout.lookup(ev);
|
||||||
|
|
||||||
|
if (isCmdOrCtrl(ev) && shiftKey && (key === 'e' || key === 'E')) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
|
||||||
|
handleReact();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
[handleReact]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function useKeyboardShortcuts(
|
export function useKeyboardShortcuts(
|
||||||
...eventHandlers: Array<KeyboardShortcutHandlerType>
|
...eventHandlers: Array<KeyboardShortcutHandlerType>
|
||||||
): void {
|
): void {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue