Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,7 @@ const CONST = {
EMOJI_NAME: /:[\p{L}0-9_+-]+:/gu,
EMOJI_SUGGESTIONS: /:[\p{L}0-9_+-]{1,40}$/u,
AFTER_FIRST_LINE_BREAK: /\n.*/g,
LINE_BREAK: /\r\n|\r|\n/g,
LINE_BREAK: /\r\n|\r|\n|\u2028/g,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When I copy from Mac notes app, the new line is https://www.compart.com/en/unicode/U+2028

CODE_2FA: /^\d{6}$/,
ATTACHMENT_ID: /chat-attachments\/(\d+)/,
HAS_COLON_ONLY_AT_THE_BEGINNING: /^:[^:]+$/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {getAllTaxRates} from '@libs/PolicyUtils';
import type {OptionData} from '@libs/ReportUtils';
import {getAutocompleteQueryWithComma, getQueryWithoutAutocompletedPart} from '@libs/SearchAutocompleteUtils';
import {buildUserReadableQueryString, getQueryWithUpdatedValues, isDefaultExpensesQuery, sanitizeSearchValue} from '@libs/SearchQueryUtils';
import StringUtils from '@libs/StringUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -130,11 +131,12 @@ function SearchPageHeaderInput({

const onSearchQueryChange = useCallback(
(userQuery: string) => {
const updatedUserQuery = getAutocompleteQueryWithComma(textInputValue, userQuery);
const singleLineUserQuery = StringUtils.lineBreaksToSpaces(userQuery, true);
const updatedUserQuery = getAutocompleteQueryWithComma(textInputValue, singleLineUserQuery);
setTextInputValue(updatedUserQuery);
setAutocompleteQueryValue(updatedUserQuery);

const updatedSubstitutionsMap = getUpdatedSubstitutionsMap(userQuery, autocompleteSubstitutions);
const updatedSubstitutionsMap = getUpdatedSubstitutionsMap(singleLineUserQuery, autocompleteSubstitutions);
if (!isEqual(autocompleteSubstitutions, updatedSubstitutionsMap)) {
setAutocompleteSubstitutions(updatedSubstitutionsMap);
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {SearchOption} from '@libs/OptionsListUtils';
import type {OptionData} from '@libs/ReportUtils';
import {getAutocompleteQueryWithComma, getQueryWithoutAutocompletedPart} from '@libs/SearchAutocompleteUtils';
import {getQueryWithUpdatedValues, sanitizeSearchValue} from '@libs/SearchQueryUtils';
import StringUtils from '@libs/StringUtils';
import Navigation from '@navigation/Navigation';
import type {ReportsSplitNavigatorParamList} from '@navigation/types';
import variables from '@styles/variables';
Expand Down Expand Up @@ -188,11 +189,12 @@ function SearchRouter({onRouterClose, shouldHideInputCaret}: SearchRouterProps,
if (autoScrollToRight) {
shouldScrollRef.current = true;
}
const updatedUserQuery = getAutocompleteQueryWithComma(textInputValue, userQuery);
const singleLineUserQuery = StringUtils.lineBreaksToSpaces(userQuery, true);
const updatedUserQuery = getAutocompleteQueryWithComma(textInputValue, singleLineUserQuery);
setTextInputValue(updatedUserQuery);
setAutocompleteQueryValue(updatedUserQuery);

const updatedSubstitutionsMap = getUpdatedSubstitutionsMap(userQuery, autocompleteSubstitutions);
const updatedSubstitutionsMap = getUpdatedSubstitutionsMap(singleLineUserQuery, autocompleteSubstitutions);
if (!isEqual(autocompleteSubstitutions, updatedSubstitutionsMap)) {
setAutocompleteSubstitutions(updatedSubstitutionsMap);
}
Expand Down
8 changes: 4 additions & 4 deletions src/libs/StringUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import deburr from 'lodash/deburr';
import CONST from '@src/CONST';
import * as Browser from './Browser';
import {isSafari} from './Browser';

/**
* Removes diacritical marks and non-alphabetic and non-latin characters from a string.
Expand Down Expand Up @@ -38,7 +38,7 @@ function removeInvisibleCharacters(value: string): string {
// - \u2060: word joiner
result = result.replace(/[\u200B\u2060]/g, '');

const invisibleCharacterRegex = Browser.isSafari() ? /([\uD800-\uDBFF][\uDC00-\uDFFF])|[\p{Cc}\p{Co}\p{Cn}]/gu : /[\p{Cc}\p{Cs}\p{Co}\p{Cn}]/gu;
const invisibleCharacterRegex = isSafari() ? /([\uD800-\uDBFF][\uDC00-\uDFFF])|[\p{Cc}\p{Co}\p{Cn}]/gu : /[\p{Cc}\p{Cs}\p{Co}\p{Cn}]/gu;

// The control unicode (Cc) regex removes all newlines,
// so we first split the string by newline and rejoin it afterward to retain the original line breaks.
Expand Down Expand Up @@ -86,8 +86,8 @@ function normalizeCRLF(value?: string): string | undefined {
/**
* Replace all line breaks with white spaces
*/
function lineBreaksToSpaces(text = '') {
return text.replace(CONST.REGEX.LINE_BREAK, ' ');
function lineBreaksToSpaces(text = '', useNonBreakingSpace = false) {
return text.replace(CONST.REGEX.LINE_BREAK, useNonBreakingSpace ? '\u00A0' : ' ');
}

/**
Expand Down