mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 22:10:21 +08:00
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:
parent
228ed474ce
commit
ed2e01491e
@ -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
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user