Enable the message right-click context menu in the browser (#8336)

* Enable the message right-click context menu in the browser

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>

* Move `getSelectedText()` to `strings.ts`

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>

* Move `canCancel()` to `EventUtils.ts`

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2022-04-15 20:12:40 +02:00 committed by GitHub
parent 1afecc474f
commit 11e0a3a8fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 15 deletions

View file

@ -70,7 +70,7 @@ import { RoomNotificationStateStore } from '../../../stores/notifications/RoomNo
import { NotificationStateEvents } from '../../../stores/notifications/NotificationState';
import { NotificationColor } from '../../../stores/notifications/NotificationColor';
import AccessibleButton, { ButtonEvent } from '../elements/AccessibleButton';
import { copyPlaintext } from '../../../utils/strings';
import { copyPlaintext, getSelectedText } from '../../../utils/strings';
import { DecryptionFailureTracker } from '../../../DecryptionFailureTracker';
import RedactedBody from '../messages/RedactedBody';
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
@ -947,13 +947,26 @@ export class UnwrappedEventTile extends React.Component<IProps, IState> {
};
private showContextMenu(ev: React.MouseEvent, showPermalink?: boolean): void {
// Return if message right-click context menu isn't enabled
if (!SettingsStore.getValue("feature_message_right_click_context_menu")) return;
// Return if we're in a browser and click either an a tag or we have
// selected text, as in those cases we want to use the native browser
// menu
const clickTarget = ev.target as HTMLElement;
if (
!PlatformPeg.get().allowOverridingNativeContextMenus() &&
(clickTarget.tagName === "a" || clickTarget.closest("a") || getSelectedText())
) return;
// There is no way to copy non-PNG images into clipboard, so we can't
// have our own handling for copying images, so we leave it to the
// Electron layer (webcontents-handler.ts)
if (ev.target instanceof HTMLImageElement) return;
if (!PlatformPeg.get().allowOverridingNativeContextMenus()) return;
// We don't want to show the menu when editing a message
if (this.props.editState) return;
ev.preventDefault();
ev.stopPropagation();
this.setState({