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

Fix emoji only is cut off if wrapped with markdown and contains whitespaces #53707

15 changes: 13 additions & 2 deletions src/components/HTMLEngineProvider/BaseHTMLEngineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ function BaseHTMLEngineProvider({textSelectable = false, children, enableExperim
}),
comment: HTMLElementModel.fromCustomModel({
tagName: 'comment',
mixedUAStyles: {whiteSpace: 'pre'},
getMixedUAStyles: (tnode) => {
if (tnode.attributes.islarge === undefined) {
return {whiteSpace: 'pre'};
}
return {whiteSpace: 'pre', ...styles.onlyEmojisText};
},
contentModel: HTMLContentModel.block,
}),
'email-comment': HTMLElementModel.fromCustomModel({
tagName: 'email-comment',
mixedUAStyles: {whiteSpace: 'normal'},
getMixedUAStyles: (tnode) => {
if (tnode.attributes.islarge === undefined) {
return {whiteSpace: 'normal'};
}
return {whiteSpace: 'normal', ...styles.onlyEmojisText};
},
contentModel: HTMLContentModel.block,
}),
strong: HTMLElementModel.fromCustomModel({
Expand Down Expand Up @@ -102,6 +112,7 @@ function BaseHTMLEngineProvider({textSelectable = false, children, enableExperim
styles.textSupporting,
styles.textLineThrough,
styles.mutedNormalTextLabel,
styles.onlyEmojisText,
styles.onlyEmojisTextLineHeight,
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ function EditedRenderer({tnode, TDefaultRenderer, style, ...defaultRendererProps
const styles = useThemeStyles();
const {translate} = useLocalize();
const isPendingDelete = !!(tnode.attributes.deleted !== undefined);
const isLarge = !!(tnode.attributes.islarge !== undefined);
return (
<Text style={isLarge && styles.onlyEmojisTextLineHeight}>
<Text fontSize={variables.fontSizeSmall}>
<Text
style={styles.userSelectNone}
fontSize={variables.fontSizeSmall}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function AttachmentCommentFragment({addExtraMargin, html, source, styleAsDeleted
return (
<View style={addExtraMargin ? styles.mt2 : {}}>
<RenderCommentHTML
containsOnlyEmojis={false}
source={source}
html={htmlContent}
/>
Expand Down
6 changes: 4 additions & 2 deletions src/pages/home/report/comment/RenderCommentHTML.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import type {OriginalMessageSource} from '@src/types/onyx/OriginalMessage';
type RenderCommentHTMLProps = {
source: OriginalMessageSource;
html: string;
containsOnlyEmojis: boolean;
};

function RenderCommentHTML({html, source}: RenderCommentHTMLProps) {
const commentHtml = source === 'email' ? `<email-comment>${html}</email-comment>` : `<comment>${html}</comment>`;
function RenderCommentHTML({html, source, containsOnlyEmojis}: RenderCommentHTMLProps) {
const commentHtml =
source === 'email' ? `<email-comment ${containsOnlyEmojis ? 'islarge' : ''}>${html}</email-comment>` : `<comment ${containsOnlyEmojis ? 'islarge' : ''}>${html}</comment>`;

return <RenderHTML html={commentHtml} />;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/comment/TextCommentFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ function TextCommentFragment({fragment, styleAsDeleted, styleAsMuted = false, so
const containsOnlyEmojis = EmojiUtils.containsOnlyEmojis(text ?? '');
const containsEmojis = CONST.REGEX.ALL_EMOJIS.test(text ?? '');
if (!shouldRenderAsText(html, text ?? '') && !(containsOnlyEmojis && styleAsDeleted)) {
const editedTag = fragment?.isEdited ? `<edited ${styleAsDeleted ? 'deleted' : ''} ${containsOnlyEmojis ? 'islarge' : ''}></edited>` : '';
const editedTag = fragment?.isEdited ? `<edited ${styleAsDeleted ? 'deleted' : ''}></edited>` : '';
const htmlWithDeletedTag = styleAsDeleted ? `<del>${html}</del>` : html;

let htmlContent = htmlWithDeletedTag;
if (containsOnlyEmojis) {
htmlContent = Str.replaceAll(htmlContent, '<emoji>', '<emoji islarge>');
htmlContent = Str.replaceAll(htmlContent, '<blockquote>', '<blockquote isemojisonly>');
} else if (containsEmojis) {
htmlContent = Str.replaceAll(htmlWithDeletedTag, '<emoji>', '<emoji ismedium>');
}
Expand All @@ -87,6 +86,7 @@ function TextCommentFragment({fragment, styleAsDeleted, styleAsMuted = false, so

return (
<RenderCommentHTML
containsOnlyEmojis={containsOnlyEmojis}
source={source}
html={htmlWithTag}
/>
Expand Down
Loading