From 6777fb5e78b22342a8c25b86c26eb8e6ca985227 Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Fri, 27 Oct 2023 20:40:02 +0530 Subject: [PATCH 1/2] emoji/mention suggestion are displayed --- src/libs/convertToLTRForComposer/index.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.ts b/src/libs/convertToLTRForComposer/index.ts index eb14bfa8c11a3..c29c27362458b 100644 --- a/src/libs/convertToLTRForComposer/index.ts +++ b/src/libs/convertToLTRForComposer/index.ts @@ -1,19 +1,27 @@ import CONST from '../../CONST'; import ConvertToLTRForComposer from './types'; -function hasLTRorRTLCharacters(text: string): boolean { - // Regular expressions to match LTR and RTL character ranges. +function hasRTLCharacters(text: string): boolean { + // Regular expressions to match RTL character ranges. + const rtlPattern = /[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/; + return rtlPattern.test(text); +} +function hasLTRCharacters(text: string): boolean { + // Regular expressions to match LTR character ranges. // eslint-disable-next-line no-control-regex const ltrPattern = /[\u0001-\u05FF\u0600-\u06FF\u0750-\u077F\uFB50-\uFDFF\uFE70-\uFEFF]/; - const rtlPattern = /[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/; - return ltrPattern.test(text) || rtlPattern.test(text); + return ltrPattern.test(text); } // Converts a given text to ensure it starts with the LTR (Left-to-Right) marker. const convertToLTRForComposer: ConvertToLTRForComposer = (text) => { - // Ensure the text contains LTR or RTL characters to avoid an unwanted special character at the beginning, even after a backspace deletion. - if (!hasLTRorRTLCharacters(text)) { + // Ensure that the text starts with RTL characters if not we return the same text to avoid concatination with special character at the start which leads to unexpected behaviour for Emoji/Mention suggestions. + if (!hasRTLCharacters(text)) { + // If text contains LTR character return the same text otherwise return an empty string to avoid an empty draft due to special character. + if (hasLTRCharacters(text)) { + return text; + } return ''; } From 11053d98a92c1045ed45fa43022bc0f3ce5ddcf6 Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Fri, 27 Oct 2023 22:31:42 +0530 Subject: [PATCH 2/2] native emoji support added --- src/libs/convertToLTRForComposer/index.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.ts b/src/libs/convertToLTRForComposer/index.ts index c29c27362458b..79c1eaed59a53 100644 --- a/src/libs/convertToLTRForComposer/index.ts +++ b/src/libs/convertToLTRForComposer/index.ts @@ -6,23 +6,16 @@ function hasRTLCharacters(text: string): boolean { const rtlPattern = /[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/; return rtlPattern.test(text); } -function hasLTRCharacters(text: string): boolean { - // Regular expressions to match LTR character ranges. - // eslint-disable-next-line no-control-regex - const ltrPattern = /[\u0001-\u05FF\u0600-\u06FF\u0750-\u077F\uFB50-\uFDFF\uFE70-\uFEFF]/; - - return ltrPattern.test(text); -} // Converts a given text to ensure it starts with the LTR (Left-to-Right) marker. const convertToLTRForComposer: ConvertToLTRForComposer = (text) => { // Ensure that the text starts with RTL characters if not we return the same text to avoid concatination with special character at the start which leads to unexpected behaviour for Emoji/Mention suggestions. if (!hasRTLCharacters(text)) { - // If text contains LTR character return the same text otherwise return an empty string to avoid an empty draft due to special character. - if (hasLTRCharacters(text)) { - return text; + // If text is empty string return empty string to avoid an empty draft due to special character. + if (text === '' || CONST.UNICODE.LTR.match(text)) { + return ''; } - return ''; + return text; } // Check if the text contains only spaces. If it does, we do not concatenate it with CONST.UNICODE.LTR,