Prevent hiding the context menu by clicking away to also potentially select messages

pull/635/head
Maxim Shishmarev 5 years ago
parent 78f97bf116
commit 2262b41cd7

@ -127,6 +127,7 @@
} }
this.selected = false; this.selected = false;
window.contextMenuShown = false;
generateProps(); generateProps();
}, },
@ -657,6 +658,7 @@
onCopyText: () => this.copyText(), onCopyText: () => this.copyText(),
onSelectMessage: () => this.selectMessage(), onSelectMessage: () => this.selectMessage(),
onSelectMessageUnchecked: () => this.selectMessageUnchecked(),
onCopyPubKey: () => this.copyPubKey(), onCopyPubKey: () => this.copyPubKey(),
onReply: () => this.trigger('reply', this), onReply: () => this.trigger('reply', this),
onRetrySend: () => this.retrySend(), onRetrySend: () => this.retrySend(),
@ -801,7 +803,7 @@
const isFromMe = contact ? contact.id === this.OUR_NUMBER : false; const isFromMe = contact ? contact.id === this.OUR_NUMBER : false;
const onClick = noClick const onClick = noClick
? null ? null
: (event) => { : event => {
event.stopPropagation(); event.stopPropagation();
this.trigger('scroll-to-message', { this.trigger('scroll-to-message', {
author, author,
@ -966,7 +968,8 @@
}); });
}, },
selectMessage() { // Select message even if the context menu is shown
selectMessageUnchecked() {
this.selected = !this.selected; this.selected = !this.selected;
const convo = this.getConversation(); const convo = this.getConversation();
@ -980,6 +983,15 @@
this.trigger('change'); this.trigger('change');
}, },
selectMessage() {
// Disable message selection when the context menu is displayed
if (window.contextMenuShown) {
return;
}
this.selectMessageUnchecked();
},
copyText() { copyText() {
clipboard.writeText(this.get('body')); clipboard.writeText(this.get('body'));
window.Whisper.events.trigger('showToast', { window.Whisper.events.trigger('showToast', {

@ -35,6 +35,7 @@ import { ContextMenu, ContextMenuTrigger, MenuItem } from 'react-contextmenu';
declare global { declare global {
interface Window { interface Window {
shortenPubkey: any; shortenPubkey: any;
contextMenuShown: boolean;
} }
} }
@ -105,6 +106,7 @@ export interface Props {
onClickLinkPreview?: (url: string) => void; onClickLinkPreview?: (url: string) => void;
onCopyText?: () => void; onCopyText?: () => void;
onSelectMessage: () => void; onSelectMessage: () => void;
onSelectMessageUnchecked: () => void;
onReply?: () => void; onReply?: () => void;
onRetrySend?: () => void; onRetrySend?: () => void;
onDownload?: (isDangerous: boolean) => void; onDownload?: (isDangerous: boolean) => void;
@ -847,7 +849,7 @@ export class Message extends React.PureComponent<Props, State> {
const { const {
attachments, attachments,
onCopyText, onCopyText,
onSelectMessage, onSelectMessageUnchecked,
direction, direction,
status, status,
isDeletable, isDeletable,
@ -876,8 +878,27 @@ export class Message extends React.PureComponent<Props, State> {
} }
}; };
const onContextMenuShown = () => {
window.contextMenuShown = true;
};
const onContextMenuHidden = () => {
// This function will called before the click event
// on the message would trigger (and I was unable to
// prevent propagation in this case), so use a short timeout
setTimeout(() => {
window.contextMenuShown = false;
}, 100);
};
// CONTEXT MENU "Select Message" does not work
return ( return (
<ContextMenu id={triggerId}> <ContextMenu
id={triggerId}
onShow={onContextMenuShown}
onHide={onContextMenuHidden}
>
{!multipleAttachments && attachments && attachments[0] ? ( {!multipleAttachments && attachments && attachments[0] ? (
<MenuItem <MenuItem
attributes={{ attributes={{
@ -895,7 +916,7 @@ export class Message extends React.PureComponent<Props, State> {
) : null} ) : null}
<MenuItem onClick={wrap(onCopyText)}>{i18n('copyMessage')}</MenuItem> <MenuItem onClick={wrap(onCopyText)}>{i18n('copyMessage')}</MenuItem>
<MenuItem onClick={wrap(onSelectMessage)}> <MenuItem onClick={wrap(onSelectMessageUnchecked)}>
{i18n('selectMessage')} {i18n('selectMessage')}
</MenuItem> </MenuItem>
<MenuItem <MenuItem

Loading…
Cancel
Save