Merge pull request #8714 from internet-development/c/app-1332-handle-autocomplete-broken-for-handles-with-hyphens
Fix some auto complete issues on mobile
This commit is contained in:
@@ -32,6 +32,7 @@ describe('getMentionAt', () => {
|
|||||||
['@alice hello', 7, undefined],
|
['@alice hello', 7, undefined],
|
||||||
['alice@alice', 0, undefined],
|
['alice@alice', 0, undefined],
|
||||||
['alice@alice', 6, undefined],
|
['alice@alice', 6, undefined],
|
||||||
|
['hello @alice-com goodbye', 8, 'alice-com'],
|
||||||
]
|
]
|
||||||
|
|
||||||
it.each(cases)(
|
it.each(cases)(
|
||||||
@@ -72,6 +73,7 @@ describe('insertMentionAt', () => {
|
|||||||
['@alice hello', 7, '@alice hello'],
|
['@alice hello', 7, '@alice hello'],
|
||||||
['alice@alice', 0, 'alice@alice'],
|
['alice@alice', 0, 'alice@alice'],
|
||||||
['alice@alice', 6, 'alice@alice'],
|
['alice@alice', 6, 'alice@alice'],
|
||||||
|
['hello @alice-com goodbye', 10, 'hello @alice.com goodbye'],
|
||||||
]
|
]
|
||||||
|
|
||||||
it.each(cases)(
|
it.each(cases)(
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export function getMentionAt(
|
|||||||
text: string,
|
text: string,
|
||||||
cursorPos: number,
|
cursorPos: number,
|
||||||
): FoundMention | undefined {
|
): FoundMention | undefined {
|
||||||
let re = /(^|\s)@([a-z0-9.]*)/gi
|
let re = /(^|\s)@([a-z0-9.-]*)/gi
|
||||||
let match
|
let match
|
||||||
while ((match = re.exec(text))) {
|
while ((match = re.exec(text))) {
|
||||||
const spaceOffset = match[1].length
|
const spaceOffset = match[1].length
|
||||||
|
|||||||
@@ -96,10 +96,11 @@ export const TextInput = forwardRef(function TextInputImpl(
|
|||||||
newRt.detectFacetsWithoutResolution()
|
newRt.detectFacetsWithoutResolution()
|
||||||
setRichText(newRt)
|
setRichText(newRt)
|
||||||
|
|
||||||
const prefix = getMentionAt(
|
// NOTE: BinaryFiddler
|
||||||
newText,
|
// onChangeText happens before onSelectionChange, cursorPos is out of bound if the user deletes characters,
|
||||||
textInputSelection.current?.start || 0,
|
const cursorPos = textInputSelection.current?.start ?? 0
|
||||||
)
|
const prefix = getMentionAt(newText, Math.min(cursorPos, newText.length))
|
||||||
|
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
setAutocompletePrefix(prefix.value)
|
setAutocompletePrefix(prefix.value)
|
||||||
} else if (autocompletePrefix) {
|
} else if (autocompletePrefix) {
|
||||||
|
|||||||
Reference in New Issue
Block a user