Skip to content

Commit

Permalink
Merge pull request #53707 from bernhardoj/fix/53546-emoji-cut-off-at-…
Browse files Browse the repository at this point in the history
…top-when-wrapped-with-md

Fix emoji only is cut off if wrapped with markdown and contains whitespaces
  • Loading branch information
youssef-lr authored Jan 10, 2025
2 parents d0a2d5e + 6b86ca8 commit d22d9b5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
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

0 comments on commit d22d9b5

Please sign in to comment.