fix(core): ai send button not work (#9688)

Hotfix this AI send button not work issue.
This commit is contained in:
Yue Wu
2025-01-14 17:14:34 +08:00
committed by GitHub
parent c7d621fd05
commit 06bd09f07c
2 changed files with 19 additions and 9 deletions
@@ -364,8 +364,7 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
}}
@keydown=${async (evt: KeyboardEvent) => {
if (evt.key === 'Enter' && !evt.shiftKey && !evt.isComposing) {
evt.preventDefault();
await this.send();
this._onTextareaSend(evt);
}
}}
@focus=${() => {
@@ -425,7 +424,7 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
${ChatAbortIcon}
</div>`
: html`<div
@click="${this.send}"
@click="${this._onTextareaSend}"
class="chat-panel-send"
aria-disabled=${this.isInputEmpty}
data-testid="chat-panel-send"
@@ -436,19 +435,30 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
</div>`;
}
send = async (input?: string) => {
private readonly _onTextareaSend = (e: MouseEvent | KeyboardEvent) => {
e.preventDefault();
e.stopPropagation();
const value = this.textarea.value.trim();
if (value.length === 0) return;
this.textarea.value = '';
this.isInputEmpty = true;
this.textarea.style.height = 'unset';
this.send(value).catch(console.error);
};
send = async (text: string) => {
const { status, markdown } = this.chatContextValue;
if (status === 'loading' || status === 'transmitting') return;
const text = input || this.textarea.value;
const { images } = this.chatContextValue;
if (!text && images.length === 0) {
return;
}
const { doc } = this.host;
this.textarea.value = '';
this.isInputEmpty = true;
this.textarea.style.height = 'unset';
this.updateContext({
images: [],
status: 'loading',
@@ -25,7 +25,7 @@ export interface AIChatParams {
export interface AISendParams {
host: EditorHost;
input?: string;
input: string;
context?: Partial<ChatContextValue | null>;
}