fix: clear @ and other input text when exiting model selection menu w… (#10427)

fix: clear @ and other input text when exiting model selection menu with Esc
This commit is contained in:
Xin Rui 2025-09-28 13:44:27 +08:00 committed by GitHub
parent 228ed474ce
commit ed2e01491e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -250,21 +250,23 @@ const MentionModelsButton: FC<Props> = ({
// ESC关闭时的处理删除 @ 和搜索文本
if (action === 'esc') {
// 只有在输入触发且有模型选择动作时才删除@字符和搜索文本
const triggerInfo = ctx?.triggerInfo ?? triggerInfoRef.current
if (
hasModelActionRef.current &&
ctx.triggerInfo?.type === 'input' &&
ctx.triggerInfo?.position !== undefined
triggerInfo?.type === 'input' &&
triggerInfo?.position !== undefined
) {
// 基于当前光标 + 搜索词精确定位并删除position 仅作兜底
setText((currentText) => {
const textArea = document.querySelector('.inputbar textarea') as HTMLTextAreaElement | null
const caret = textArea ? (textArea.selectionStart ?? currentText.length) : currentText.length
return removeAtSymbolAndText(currentText, caret, searchText || '', ctx.triggerInfo?.position!)
return removeAtSymbolAndText(currentText, caret, searchText || '', triggerInfo.position!)
})
}
}
// Backspace删除@的情况delete-symbol
// @ 已经被Backspace自然删除面板关闭不需要额外操作
triggerInfoRef.current = undefined
}
})
},