fix: undesired assistant selection menu popup when no ' ' before '@'
This commit is contained in:
parent
3108a1c0b3
commit
28c0748001
@ -231,14 +231,14 @@ const MentionModelsButton: FC<Props> = ({ mentionModels, onMentionModel: onSelec
|
|||||||
const cursorPosition = textArea.selectionStart
|
const cursorPosition = textArea.selectionStart
|
||||||
const textBeforeCursor = textArea.value.substring(0, cursorPosition)
|
const textBeforeCursor = textArea.value.substring(0, cursorPosition)
|
||||||
const lastAtIndex = textBeforeCursor.lastIndexOf('@')
|
const lastAtIndex = textBeforeCursor.lastIndexOf('@')
|
||||||
|
const textBeforeLastAt = textBeforeCursor.slice(0, lastAtIndex)
|
||||||
if (lastAtIndex === -1 || textBeforeCursor.slice(lastAtIndex + 1).includes(' ')) {
|
if (lastAtIndex === -1 || textBeforeCursor.slice(lastAtIndex + 1).includes(' ')) {
|
||||||
setIsOpen(false)
|
setIsOpen(false)
|
||||||
setSearchText('')
|
setSearchText('')
|
||||||
setMenuDismissed(false) // Reset dismissed flag when @ is removed
|
setMenuDismissed(false) // Reset dismissed flag when @ is removed
|
||||||
} else {
|
} else {
|
||||||
// Only open menu if it wasn't explicitly dismissed
|
// Only open menu if it wasn't explicitly dismissed
|
||||||
if (!menuDismissed) {
|
if (!menuDismissed && (textBeforeLastAt.slice(-1) === ' ' || lastAtIndex === 0)) {
|
||||||
setIsOpen(true)
|
setIsOpen(true)
|
||||||
const searchStr = textBeforeCursor.slice(lastAtIndex + 1)
|
const searchStr = textBeforeCursor.slice(lastAtIndex + 1)
|
||||||
setSearchText(searchStr)
|
setSearchText(searchStr)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user