Message Context Menu: Fix showing Copy Selected Text on wrong messages (#4512)
This commit is contained in:
parent
5a7416d750
commit
3a1c87fcb0
@ -4,6 +4,7 @@ import { ApiMediaFormat } from '../../../../api/types';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
getMessageContact,
|
getMessageContact,
|
||||||
|
getMessageHtmlId,
|
||||||
getMessageMediaHash,
|
getMessageMediaHash,
|
||||||
getMessagePhoto,
|
getMessagePhoto,
|
||||||
getMessageText,
|
getMessageText,
|
||||||
@ -76,6 +77,7 @@ export function getMessageCopyOptions(
|
|||||||
selection?.anchorNode?.parentNode
|
selection?.anchorNode?.parentNode
|
||||||
&& (selection.anchorNode.parentNode as HTMLElement).closest('.Message .content-inner')
|
&& (selection.anchorNode.parentNode as HTMLElement).closest('.Message .content-inner')
|
||||||
&& selection.toString().replace(/(?:\r\n|\r|\n)/g, '') !== ''
|
&& selection.toString().replace(/(?:\r\n|\r|\n)/g, '') !== ''
|
||||||
|
&& checkMessageHasSelection(message)
|
||||||
));
|
));
|
||||||
|
|
||||||
options.push({
|
options.push({
|
||||||
@ -121,7 +123,12 @@ export function getMessageCopyOptions(
|
|||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
function checkMessageHasSelection(message: ApiMessage): boolean {
|
||||||
|
const selection = window.getSelection();
|
||||||
|
const selectionParentNode = (selection?.anchorNode?.parentNode as HTMLElement);
|
||||||
|
const selectedMessageElement = selectionParentNode?.closest<HTMLDivElement>('.Message.message-list-item');
|
||||||
|
return getMessageHtmlId(message.id) === selectedMessageElement?.id;
|
||||||
|
}
|
||||||
function getCopyLabel(hasSelection: boolean): string {
|
function getCopyLabel(hasSelection: boolean): string {
|
||||||
if (hasSelection) {
|
if (hasSelection) {
|
||||||
return 'lng_context_copy_selected';
|
return 'lng_context_copy_selected';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user