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

emoji/mention suggestion are displayed #30521

Merged
Changes from 1 commit
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
20 changes: 14 additions & 6 deletions src/libs/convertToLTRForComposer/index.ts
Original file line number Diff line number Diff line change
@@ -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 '';
}

Expand Down
Loading