Fix rendering of mentions in composer
This commit is contained in:
parent
0ac6c0ff61
commit
9d13e05dbf
1 changed files with 19 additions and 14 deletions
|
@ -108,19 +108,24 @@ export const ComposePost = observer(function ComposePost({
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const textDecorated = useMemo(() => {
|
const textDecorated = useMemo(() => {
|
||||||
return (text || '').split(/(\s)/g).map((item, i) => {
|
const re = /(@[a-z0-9\.]*)/gi
|
||||||
if (
|
const segments = []
|
||||||
/^@[a-zA-Z0-9\.-]+$/g.test(item) &&
|
let match
|
||||||
autocompleteView.knownHandles.has(item.slice(1))
|
let start = 0
|
||||||
) {
|
let i = 0
|
||||||
return (
|
while ((match = re.exec(text))) {
|
||||||
<Text key={i} style={{color: colors.blue3}}>
|
segments.push(text.slice(start, match.index))
|
||||||
{item}
|
segments.push(
|
||||||
</Text>
|
<Text key={i++} style={{color: colors.blue3}}>
|
||||||
)
|
{match[0]}
|
||||||
}
|
</Text>,
|
||||||
return item
|
)
|
||||||
})
|
start = match.index + match[0].length
|
||||||
|
}
|
||||||
|
if (start < text.length) {
|
||||||
|
segments.push(text.slice(start))
|
||||||
|
}
|
||||||
|
return segments
|
||||||
}, [text])
|
}, [text])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -194,7 +199,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const atPrefixRegex = /@([\S]*)$/i
|
const atPrefixRegex = /@([a-z0-9\.]*)$/i
|
||||||
function extractTextAutocompletePrefix(text: string) {
|
function extractTextAutocompletePrefix(text: string) {
|
||||||
const match = atPrefixRegex.exec(text)
|
const match = atPrefixRegex.exec(text)
|
||||||
if (match) {
|
if (match) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue