Skip to content

feat:addition of copy link in the context menu #1457

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ export const MessageContextMenu = (props: Props) => {
MessageInteraction.copyBodyToClipboard(text);
}, [text]);

const copyLinkFromMessage = useCallback(() => {
const linkMatch = text?.match(/https?:\/\/[^\s]+/);
const firstLink = linkMatch?.[0];

if (firstLink) {
navigator.clipboard.writeText(firstLink).then(() => {
window.log.info('Link copied to clipboard');
});
} else {
window.log.warn('No link found in message');
}
}, [text]);


const onSelect = useCallback(() => {
dispatch(toggleSelectedMessageId(messageId));
}, [dispatch, messageId]);
Expand Down Expand Up @@ -331,6 +345,7 @@ export const MessageContextMenu = (props: Props) => {
</ItemWithDataTestId>
) : null}
<ItemWithDataTestId onClick={copyText}>{window.i18n('copy')}</ItemWithDataTestId>
<ItemWithDataTestId onClick={copyLinkFromMessage}>{window.i18n('copyMessageLink') ?? 'Copy link in message'}</ItemWithDataTestId>
<ItemWithDataTestId
onClick={() => {
void showMessageInfoOverlay({ messageId, dispatch });
Expand Down