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: (Redo) Copying the messages and marking a message in between as unread generates 'new' in the text #18684

4 changes: 4 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,10 @@ const CONST = {
ACTIVE: 'active',
DISABLED: 'disabled',
},

// This ID is used in SelectionScraper.js to query the DOM for UnreadActionIndicator's
// div and then remove it from copied contents in the getHTMLOfSelection() method.
UNREAD_ACTION_INDICATOR_ID: 'no-copy-area-unread-action-indicator',
};

export default CONST;
4 changes: 3 additions & 1 deletion src/components/UnreadActionIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import React from 'react';
import {View} from 'react-native';
import styles from '../styles/styles';
import Text from './Text';
import CONST from '../CONST';
import withLocalize, {withLocalizePropTypes} from './withLocalize';

const UnreadActionIndicator = (props) => (
<View
accessibilityLabel={props.translate('accessibilityHints.newMessageLineIndicator')}
data-action-id={props.reportActionID}
style={styles.unreadIndicatorContainer}
style={[styles.unreadIndicatorContainer, styles.userSelectNone]}
nativeID={CONST.UNREAD_ACTION_INDICATOR_ID}
>
<View style={styles.unreadIndicatorLine} />
<Text style={styles.unreadIndicatorText}>{props.translate('common.new')}</Text>
Expand Down
9 changes: 9 additions & 0 deletions src/libs/SelectionScraper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import render from 'dom-serializer';
import {parseDocument} from 'htmlparser2';
import _ from 'underscore';
import Str from 'expensify-common/lib/str';
import CONST from '../../CONST';

const elementsWillBeSkipped = ['html', 'body'];
const tagAttribute = 'data-testid';
Expand Down Expand Up @@ -80,6 +81,14 @@ const getHTMLOfSelection = () => {
}
}

// Find and remove the div housing the UnreadActionIndicator because we don't want
// the 'New/Nuevo' text inside it being copied.
const newMessageLineIndicatorDiv = div.querySelector(`#${CONST.UNREAD_ACTION_INDICATOR_ID}`);

if (newMessageLineIndicatorDiv) {
newMessageLineIndicatorDiv.remove();
}

return div.innerHTML;
};

Expand Down