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

Remove whitespace: pre because of extra empty lines bug #9195

Merged
merged 10 commits into from
Jul 15, 2022
5 changes: 5 additions & 0 deletions src/components/HTMLEngineProvider/BaseHTMLEngineProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const customHTMLElementModels = {
}),
comment: defaultHTMLElementModels.div.extend({
tagName: 'comment',
mixedUAStyles: {whiteSpace: 'pre'},
}),
'email-comment': defaultHTMLElementModels.div.extend({
tagName: 'email-comment',
mixedUAStyles: {whiteSpace: 'normal'},
}),
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/HTMLEngineProvider/htmlEngineUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function computeEmbeddedMaxWidth(tagName, contentWidth) {
function isInsideComment(tnode) {
let currentNode = tnode;
while (currentNode.parent) {
if (currentNode.domNode.name === 'comment') {
if (currentNode.domNode.name === 'comment' || currentNode.domNode.name === 'email-comment') {
return true;
}
currentNode = currentNode.parent;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/SelectionScraper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const replaceNodes = (dom) => {
}

// Adding a new line after each comment here, because adding after each range is not working for chrome.
if (dom.attribs[tagAttribute] === 'comment') {
if (dom.attribs[tagAttribute] === 'comment' || dom.attribs[tagAttribute] === 'email-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.

Maybe we should have a function like

function isCommentTag(nodeTag) {
    return nodeTag === 'email-comment' || nodeTag === 'comment';
}

dom.children.push(new Element('br', {}));
}
}
Expand Down
56 changes: 36 additions & 20 deletions src/pages/home/report/ReportActionItemFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const propTypes = {
/** Does this fragment belong to a reportAction that has not yet loaded? */
loading: PropTypes.bool,

/** The reportAction's source */
source: PropTypes.string,

/** Should this fragment be contained in a single line? */
isSingleLine: PropTypes.bool,

Expand All @@ -64,6 +67,7 @@ const defaultProps = {
loading: false,
isSingleLine: false,
tooltipText: '',
source: '',
};

const ReportActionItemFragment = (props) => {
Expand All @@ -86,39 +90,51 @@ const ReportActionItemFragment = (props) => {
)
);
}
let {html, text} = props.fragment;

// If the only difference between fragment.text and fragment.html is <br /> tags
// we replace them with line breaks and render it as text, not as html.
// This is done to render emojis with line breaks between them as text.
const differByLineBreaksOnly = Str.replaceAll(props.fragment.html, '<br />', ' ') === props.fragment.text;
if (differByLineBreaksOnly) {
const textWithLineBreaks = Str.replaceAll(props.fragment.html, '<br />', '\n');
// eslint-disable-next-line no-param-reassign
props.fragment = {...props.fragment, text: textWithLineBreaks, html: textWithLineBreaks};
html = textWithLineBreaks;
text = textWithLineBreaks;
}

// Only render HTML if we have html in the fragment
return props.fragment.html !== props.fragment.text
? (
if (html !== text) {
if (props.source === 'email') {
// Messages from email replies usually have complex HTML structure and they don't rely in white-space: pre to preserve spacing,
// instead, the normally use &nbsp;
return (
<RenderHTML
html={`<email-comment>${html + (props.fragment.isEdited ? '<edited></edited>' : '')}</email-comment>`}
/>
);
}
return (
<RenderHTML
html={`<comment>${props.fragment.html + (props.fragment.isEdited ? '<edited></edited>' : '')}</comment>`}
html={`<comment>${html + (props.fragment.isEdited ? '<edited></edited>' : '')}</comment>`}
/>
) : (
<Text
selectable={!canUseTouchScreen() || !props.isSmallScreenWidth}
style={EmojiUtils.containsOnlyEmojis(props.fragment.text) ? styles.onlyEmojisText : undefined}
>
{Str.htmlDecode(props.fragment.text)}
{props.fragment.isEdited && (
<Text
fontSize={variables.fontSizeSmall}
color={themeColors.textSupporting}
>
{` ${props.translate('reportActionCompose.edited')}`}
</Text>
)}
</Text>
);
}
return (
<Text
selectable={!canUseTouchScreen() || !props.isSmallScreenWidth}
style={EmojiUtils.containsOnlyEmojis(text) ? styles.onlyEmojisText : undefined}
>
{Str.htmlDecode(text)}
{props.fragment.isEdited && (
<Text
fontSize={variables.fontSizeSmall}
color={themeColors.textSupporting}
>
{` ${props.translate('reportActionCompose.edited')}`}
</Text>
)}
</Text>
);
}
case 'TEXT':
return (
Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/report/ReportActionItemMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import styles from '../../../styles/styles';
import ReportActionItemFragment from './ReportActionItemFragment';
import reportActionPropTypes from './reportActionPropTypes';
Expand Down Expand Up @@ -33,6 +34,7 @@ const ReportActionItemMessage = (props) => {
isAttachment={props.action.isAttachment}
attachmentInfo={props.action.attachmentInfo}
loading={props.action.loading}
source={lodashGet(props.action, 'originalMessage.source')}
/>
))}
</View>
Expand Down
1 change: 0 additions & 1 deletion src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ const webViewStyles = {
fontSize: variables.fontSizeNormal,
fontFamily: fontFamily.GTA,
flex: 1,
whiteSpace: 'pre',
},
};

Expand Down