From ed2e01491edc94a0bda6a66d433d3e5c13badc11 Mon Sep 17 00:00:00 2001 From: Xin Rui <71483384+Konjac-XZ@users.noreply.github.com> Date: Sun, 28 Sep 2025 13:44:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20clear=20@=20and=20other=20input=20text?= =?UTF-8?q?=20when=20exiting=20model=20selection=20menu=20w=E2=80=A6=20(#1?= =?UTF-8?q?0427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: clear @ and other input text when exiting model selection menu with Esc --- .../src/pages/home/Inputbar/MentionModelsButton.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx b/src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx index 6bb36f988a..23c8fd13f5 100644 --- a/src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx +++ b/src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx @@ -250,21 +250,23 @@ const MentionModelsButton: FC = ({ // 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 } }) },