Skip to content

Commit

Permalink
fix(core): ai send button not work
Browse files Browse the repository at this point in the history
  • Loading branch information
akumatus committed Jan 14, 2025
1 parent c7d621f commit e35f12d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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=${() => {
Expand Down Expand Up @@ -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"
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface AIChatParams {

export interface AISendParams {
host: EditorHost;
input?: string;
input: string;
context?: Partial<ChatContextValue | null>;
}

Expand Down

0 comments on commit e35f12d

Please sign in to comment.