diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/strings/mention-manip.ts | 2 | ||||
-rw-r--r-- | src/view/com/composer/text-input/TextInput.tsx | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/lib/strings/mention-manip.ts b/src/lib/strings/mention-manip.ts index 1f7cbe434..7b52f745b 100644 --- a/src/lib/strings/mention-manip.ts +++ b/src/lib/strings/mention-manip.ts @@ -7,7 +7,7 @@ export function getMentionAt( text: string, cursorPos: number, ): FoundMention | undefined { - let re = /(^|\s)@([a-z0-9.]*)/gi + let re = /(^|\s)@([a-z0-9.-]*)/gi let match while ((match = re.exec(text))) { const spaceOffset = match[1].length diff --git a/src/view/com/composer/text-input/TextInput.tsx b/src/view/com/composer/text-input/TextInput.tsx index e9c5d86b9..ea92d0b91 100644 --- a/src/view/com/composer/text-input/TextInput.tsx +++ b/src/view/com/composer/text-input/TextInput.tsx @@ -96,10 +96,11 @@ export const TextInput = forwardRef(function TextInputImpl( newRt.detectFacetsWithoutResolution() setRichText(newRt) - const prefix = getMentionAt( - newText, - textInputSelection.current?.start || 0, - ) + // NOTE: BinaryFiddler + // onChangeText happens before onSelectionChange, cursorPos is out of bound if the user deletes characters, + const cursorPos = textInputSelection.current?.start ?? 0 + const prefix = getMentionAt(newText, Math.min(cursorPos, newText.length)) + if (prefix) { setAutocompletePrefix(prefix.value) } else if (autocompletePrefix) { |