Message: Support click-to-copy for code entities (#1775)
This commit is contained in:
parent
539bd66a1d
commit
9ceea488f9
@ -4,6 +4,8 @@ import { getActions } from '../../../global';
|
||||
|
||||
import { ApiFormattedText, ApiMessageEntity, ApiMessageEntityTypes } from '../../../api/types';
|
||||
import renderText, { TextFilter } from './renderText';
|
||||
import { copyTextToClipboard } from '../../../util/clipboard';
|
||||
import { getTranslation } from '../../../util/langProvider';
|
||||
|
||||
import MentionLink from '../../middle/message/MentionLink';
|
||||
import SafeLink from '../SafeLink';
|
||||
@ -334,7 +336,11 @@ function processEntity(
|
||||
</a>
|
||||
);
|
||||
case ApiMessageEntityTypes.Code:
|
||||
return <code className="text-entity-code">{renderNestedMessagePart()}</code>;
|
||||
return (
|
||||
<code className="text-entity-code" onClick={handleCodeClick} role="textbox" tabIndex={0}>
|
||||
{renderNestedMessagePart()}
|
||||
</code>
|
||||
);
|
||||
case ApiMessageEntityTypes.Email:
|
||||
return (
|
||||
<a
|
||||
@ -461,3 +467,10 @@ function handleHashtagClick(e: MouseEvent<HTMLAnchorElement>) {
|
||||
getActions().setLocalTextSearchQuery({ query: e.currentTarget.innerText });
|
||||
getActions().searchTextMessagesLocal();
|
||||
}
|
||||
|
||||
function handleCodeClick(e: MouseEvent<HTMLElement>) {
|
||||
copyTextToClipboard(e.currentTarget.innerText);
|
||||
getActions().showNotification({
|
||||
message: getTranslation('TextCopied'),
|
||||
});
|
||||
}
|
||||
|
||||
@ -821,4 +821,5 @@
|
||||
padding: 1px 2px;
|
||||
border-radius: 4px;
|
||||
font-size: calc(var(--message-text-size, 1rem) - 0.0625rem);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user