Skip to content

Commit

Permalink
use existing function
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Mar 4, 2025
1 parent 1b8dff8 commit d74809f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
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,
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,7 +131,7 @@ function SearchPageHeaderInput({

const onSearchQueryChange = useCallback(
(userQuery: string) => {
const singleLineUserQuery = userQuery.replace(/\n/g, "\u00A0");
const singleLineUserQuery = StringUtils.lineBreaksToSpaces(userQuery, true);
const updatedUserQuery = getAutocompleteQueryWithComma(textInputValue, singleLineUserQuery);
setTextInputValue(updatedUserQuery);
setAutocompleteQueryValue(updatedUserQuery);
Expand Down
3 changes: 2 additions & 1 deletion 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,7 +189,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret}: SearchRouterProps,
if (autoScrollToRight) {
shouldScrollRef.current = true;
}
const singleLineUserQuery = userQuery.replace(/\n/g, "\u00A0");
const singleLineUserQuery = StringUtils.lineBreaksToSpaces(userQuery, true);
const updatedUserQuery = getAutocompleteQueryWithComma(textInputValue, singleLineUserQuery);
setTextInputValue(updatedUserQuery);
setAutocompleteQueryValue(updatedUserQuery);
Expand Down
4 changes: 2 additions & 2 deletions src/libs/StringUtils.ts
Original file line number Diff line number Diff line change
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

0 comments on commit d74809f

Please sign in to comment.