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