mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
iOS almost working
This commit is contained in:
49
src/screens/Compose/updateText.ts
Normal file
49
src/screens/Compose/updateText.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { Dispatch } from 'react'
|
||||
import formatText from './formatText'
|
||||
import { ComposeAction, ComposeState } from './utils/types'
|
||||
|
||||
const updateText = ({
|
||||
composeState,
|
||||
composeDispatch,
|
||||
newText,
|
||||
type
|
||||
}: {
|
||||
composeState: ComposeState
|
||||
composeDispatch: Dispatch<ComposeAction>
|
||||
newText: string
|
||||
type: 'emoji' | 'suggestion'
|
||||
}) => {
|
||||
const textInput = composeState.textInputFocus.current
|
||||
if (composeState[textInput].raw.length) {
|
||||
const contentFront = composeState[textInput].raw.slice(
|
||||
0,
|
||||
composeState[textInput].selection.start
|
||||
)
|
||||
const contentRear = composeState[textInput].raw.slice(
|
||||
composeState[textInput].selection.end
|
||||
)
|
||||
|
||||
const whiteSpaceFront = /\s/g.test(contentFront.slice(-1))
|
||||
const whiteSpaceRear = /\s/g.test(contentRear.slice(-1))
|
||||
|
||||
const newTextWithSpace = `${
|
||||
whiteSpaceFront || type === 'suggestion' ? '' : ' '
|
||||
}${newText}${whiteSpaceRear ? '' : ' '}`
|
||||
|
||||
formatText({
|
||||
textInput,
|
||||
composeDispatch,
|
||||
content: [contentFront, newTextWithSpace, contentRear].join(''),
|
||||
disableDebounce: true
|
||||
})
|
||||
} else {
|
||||
formatText({
|
||||
textInput,
|
||||
composeDispatch,
|
||||
content: `${newText} `,
|
||||
disableDebounce: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default updateText
|
Reference in New Issue
Block a user