Skip to content

Commit

Permalink
Merge pull request #55932 from prakashbask/fix/53718
Browse files Browse the repository at this point in the history
Web - Chat - Pasted message not always displays no hyperlink format w…
  • Loading branch information
jasperhuangg authored Feb 6, 2025
2 parents beafd48 + 9ed76b2 commit 4987f62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/hooks/useHtmlPaste/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useCallback, useEffect} from 'react';
import {isMobile} from '@libs/Browser';
import Parser from '@libs/Parser';
import CONST from '@src/CONST';
import type UseHtmlPaste from './types';
Expand Down Expand Up @@ -89,9 +90,14 @@ const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, isActive
*/
const handlePastePlainText = useCallback(
(event: ClipboardEvent) => {
const plainText = event.clipboardData?.getData('text/plain');
if (plainText) {
paste(plainText);
const markdownText = event.clipboardData?.getData('text/plain');
// Updated paste logic to address issue #53718
// When copying from a chat conversation, the clipboard contains markdown-formatted text.
// On desktop web, users have the option to paste as plain text, but this feature is unavailable on mobile web.
// A conditional check is added to determine whether to retain markdown or convert it to plain text based on the platform.
if (markdownText) {
const parsedText = isMobile() ? markdownText : Parser.htmlToText(Parser.replace(markdownText));
paste(parsedText);
}
},
[paste],
Expand Down
6 changes: 2 additions & 4 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ function setClipboardMessage(content: string | undefined) {
if (!Clipboard.canSetHtml()) {
Clipboard.setString(Parser.htmlToMarkdown(content));
} else {
const anchorRegex = CONST.REGEX_LINK_IN_ANCHOR;
const isAnchorTag = anchorRegex.test(content);
const plainText = isAnchorTag ? Parser.htmlToMarkdown(content) : Parser.htmlToText(content);
Clipboard.setHtml(content, plainText);
const markdownText = Parser.htmlToMarkdown(content);
Clipboard.setHtml(content, markdownText);
}
}

Expand Down

0 comments on commit 4987f62

Please sign in to comment.