-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29434 from HardikChoudhary24/fix/28149-wrong-RTL-…
…text-cursor-position RTL Text gets renderd properly
- Loading branch information
Showing
6 changed files
with
61 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ConvertToLTRForComposer from './types'; | ||
|
||
/** | ||
* Android only - Do not convert RTL text to a LTR text for input box using Unicode controls. | ||
* Android does not properly support bidirectional text for mixed content for input box | ||
*/ | ||
const convertToLTRForComposer: ConvertToLTRForComposer = (text) => text; | ||
export default convertToLTRForComposer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import CONST from '../../CONST'; | ||
import ConvertToLTRForComposer from './types'; | ||
|
||
function hasLTRorRTLCharacters(text: string): boolean { | ||
// Regular expressions to match LTR and RTL 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); | ||
} | ||
|
||
// 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)) { | ||
return ''; | ||
} | ||
|
||
// Check if the text contains only spaces. If it does, we do not concatenate it with CONST.UNICODE.LTR, | ||
// as doing so would alter the normal behavior of the input box. | ||
if (/^\s*$/.test(text)) { | ||
return text; | ||
} | ||
|
||
// Check if the text already starts with the LTR marker (if so, return as is). | ||
if (text.startsWith(CONST.UNICODE.LTR)) { | ||
return text; | ||
} | ||
|
||
// Add the LTR marker to the beginning of the text. | ||
return `${CONST.UNICODE.LTR}${text}`; | ||
}; | ||
export default convertToLTRForComposer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type ConvertToLTRForComposer = (text: string) => string; | ||
|
||
export default ConvertToLTRForComposer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters