Skip to content

Commit

Permalink
native emoji support added
Browse files Browse the repository at this point in the history
  • Loading branch information
HardikChoudhary24 committed Oct 27, 2023
1 parent 6777fb5 commit 11053d9
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/libs/convertToLTRForComposer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 11053d9

Please sign in to comment.