clone richtext if we are going to mutate it
This commit is contained in:
@@ -215,12 +215,14 @@ export const TextInput = forwardRef(function TextInputImpl(
|
|||||||
const splitter = useMemo(() => new Graphemer(), [])
|
const splitter = useMemo(() => new Graphemer(), [])
|
||||||
const textDecorated = useMemo(() => {
|
const textDecorated = useMemo(() => {
|
||||||
let excess
|
let excess
|
||||||
|
let rt = richtext
|
||||||
if (richtext.graphemeLength > MAX_GRAPHEME_LENGTH) {
|
if (richtext.graphemeLength > MAX_GRAPHEME_LENGTH) {
|
||||||
|
rt = richtext.clone()
|
||||||
const split = splitter.splitGraphemes(richtext.text)
|
const split = splitter.splitGraphemes(richtext.text)
|
||||||
const validText = split.slice(0, MAX_GRAPHEME_LENGTH).join('')
|
const validText = split.slice(0, MAX_GRAPHEME_LENGTH).join('')
|
||||||
const validUnicode = new UnicodeString(validText)
|
const validUnicode = new UnicodeString(validText)
|
||||||
const excessText = split.slice(MAX_GRAPHEME_LENGTH).join('')
|
const excessText = split.slice(MAX_GRAPHEME_LENGTH).join('')
|
||||||
richtext.delete(validUnicode.utf8.byteLength, richtext.length)
|
rt.delete(validUnicode.utf8.byteLength, richtext.length)
|
||||||
excess = (
|
excess = (
|
||||||
<RNText
|
<RNText
|
||||||
key="excess"
|
key="excess"
|
||||||
@@ -235,7 +237,7 @@ export const TextInput = forwardRef(function TextInputImpl(
|
|||||||
}
|
}
|
||||||
let i = 0
|
let i = 0
|
||||||
|
|
||||||
const segments = Array.from(richtext.segments()).map(segment => {
|
const segments = Array.from(rt.segments()).map(segment => {
|
||||||
return (
|
return (
|
||||||
<RNText
|
<RNText
|
||||||
key={i++}
|
key={i++}
|
||||||
|
|||||||
Reference in New Issue
Block a user