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

Web - Chat - Pasted message not always displays no hyperlink format w… #55932

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 5 additions & 3 deletions src/hooks/useHtmlPaste/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useCallback, useEffect} from 'react';
import Parser from '@libs/Parser';
import CONST from '@src/CONST';
import isMobile from '@src/utils/isMobile';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import isMobile from '@src/utils/isMobile';
import isMobile from '@libs/Browser';

We can use isMobile from @libs/browser

import type UseHtmlPaste from './types';

const insertAtCaret = (target: HTMLElement, insertedText: string, maxLength: number) => {
Expand Down Expand Up @@ -89,9 +90,10 @@ 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');
if (markdownText) {
const parsedText = isMobile() ? markdownText : Parser.htmlToText(Parser.replace(markdownText));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment about why we need to do this and also provide a link to the issue in the comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment and mentioned issue number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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
5 changes: 5 additions & 0 deletions src/utils/isMobile/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Platform} from 'react-native';

const isMobile = () => ['ios', 'android'].includes(Platform.OS);

export default isMobile;
3 changes: 3 additions & 0 deletions src/utils/isMobile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isMobile = () => /Mobi|Android|iPhone|iPad|iPod|Windows Phone/i.test(navigator?.userAgent || '');

export default isMobile;