Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only select message data on triple click #6500

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion ts/components/conversation/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export enum GiftBadgeStates {
Opened = 'Opened',
Redeemed = 'Redeemed',
}

export type GiftBadgeType = {
expiration: number;
id: string | undefined;
Expand Down Expand Up @@ -390,6 +391,8 @@ export class Message extends React.PureComponent<Props, State> {
current: false,
};

private metadataRef: React.RefObject<HTMLDivElement> = React.createRef();

public reactionsContainerRefMerger = createRefMerger();

public expirationCheckInterval: NodeJS.Timeout | undefined;
Expand Down Expand Up @@ -823,6 +826,7 @@ export class Message extends React.PureComponent<Props, State> {
isTapToViewExpired={isTapToViewExpired}
onWidthMeasured={isInline ? this.updateMetadataWidth : undefined}
pushPanelForConversation={pushPanelForConversation}
ref={this.metadataRef}
retryMessageSend={retryMessageSend}
showEditHistoryModal={showEditHistoryModal}
status={status}
Expand Down Expand Up @@ -1779,7 +1783,7 @@ export class Message extends React.PureComponent<Props, State> {
}

return (
<div
<div // eslint-disable-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
className={classNames(
'module-message__text',
`module-message__text--${direction}`,
Expand All @@ -1790,6 +1794,18 @@ export class Message extends React.PureComponent<Props, State> {
? 'module-message__text--delete-for-everyone'
: null
)}
onClick={e => {
// Prevent metadata from being selected on triple clicks.
const clickCount = e.detail;
const range = window.getSelection()?.getRangeAt(0);
if (
clickCount === 3 &&
this.metadataRef.current &&
range?.intersectsNode(this.metadataRef.current)
) {
range.setEndBefore(this.metadataRef.current);
}
}}
onDoubleClick={(event: React.MouseEvent) => {
// Prevent double-click interefering with interactions _inside_
// the bubble.
Expand Down
Loading
Loading