From 224913b7d37cc7ca9ff0ceea6abf4814a5ef2b66 Mon Sep 17 00:00:00 2001 From: troyeguo <13820674+troyeguo@users.noreply.github.com> Date: Thu, 1 Oct 2026 14:57:11 +0800 Subject: [PATCH] feat: streamline question sending logic and enhance textarea behavior --- .../popups/popupAssist/component.tsx | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/components/popups/popupAssist/component.tsx b/src/components/popups/popupAssist/component.tsx index 5f7a5301..a3a59ed8 100644 --- a/src/components/popups/popupAssist/component.tsx +++ b/src/components/popups/popupAssist/component.tsx @@ -518,14 +518,13 @@ class PopupAssist extends React.Component { )} - {item.role === "assistant" && - index === message.length - 1 && ( -
- {this.props.t( - "AI-generated content is for reference only. Please verify carefully as it does not constitute professional advice." - )} -
- )} + {item.role === "assistant" && index === message.length - 1 && ( +
+ {this.props.t( + "AI-generated content is for reference only. Please verify carefully as it does not constitute professional advice." + )} +
+ )} ); }); @@ -574,6 +573,19 @@ class PopupAssist extends React.Component { this.setState({ chatHistory: [] }); } }; + handleSendQuestion = () => { + if (this.state.answer || this.state.isWaiting) { + return; + } + this.handleNewQuestion(this.state.inputQuestion); + this.setState({ inputQuestion: "" }, () => { + const el = this.textareaRef.current; + if (el) { + el.style.height = "40px"; + el.style.overflowY = "hidden"; + } + }); + }; handleNewQuestion = (question: string) => { if (this.state.mode === "ask") { this.setState( @@ -897,6 +909,18 @@ class PopupAssist extends React.Component { marginRight: "10px", marginBottom: "0px", }} + onKeyDown={( + event: React.KeyboardEvent + ) => { + if ( + event.key === "Enter" && + (event.ctrlKey || event.metaKey) && + !(event.nativeEvent as any).isComposing + ) { + event.preventDefault(); + this.handleSendQuestion(); + } + }} onContextMenu={() => { handleContextMenu("trans-add-content-box"); }} @@ -914,19 +938,7 @@ class PopupAssist extends React.Component { />
{ - if (this.state.answer || this.state.isWaiting) { - return; - } - this.handleNewQuestion(this.state.inputQuestion); - this.setState({ inputQuestion: "" }, () => { - const el = this.textareaRef.current; - if (el) { - el.style.height = "40px"; - el.style.overflowY = "hidden"; - } - }); - }} + onClick={this.handleSendQuestion} > {this.props.t("Send")}