From e35f12d4acdb455c0a90ceda9e2b2a049f57feef Mon Sep 17 00:00:00 2001 From: Yue Wu Date: Tue, 14 Jan 2025 16:47:08 +0800 Subject: [PATCH] fix(core): ai send button not work --- .../presets/ai/chat-panel/chat-panel-input.ts | 26 +++++++++++++------ .../src/blocksuite/presets/ai/provider.ts | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts index 72573cd68e09f..7530b7e2fc80c 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts @@ -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} ` : html`
`; } - 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', diff --git a/packages/frontend/core/src/blocksuite/presets/ai/provider.ts b/packages/frontend/core/src/blocksuite/presets/ai/provider.ts index 2fcac2e24ecd4..cb5a22a23a9cc 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/provider.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/provider.ts @@ -25,7 +25,7 @@ export interface AIChatParams { export interface AISendParams { host: EditorHost; - input?: string; + input: string; context?: Partial; }