Skip to content

Commit d1459cf

Browse files
committed
feat(chat): Support input suggestion modifiers
* Cmd/Ctrl + (event) = force submitting * Alt/Opt + (event) = force setting without submitting
1 parent ddb9edd commit d1459cf

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

js/chat/chat.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,23 +410,31 @@ class ChatContainer extends LightElement {
410410
}
411411
}
412412

413-
#onInputSuggestionClick(e: Event): void {
414-
this.#applySuggestion(e);
413+
#onInputSuggestionClick(e: MouseEvent): void {
414+
this.#onInputSuggestionEvent(e);
415415
}
416416

417417
#onInputSuggestionKeydown(e: KeyboardEvent): void {
418-
const isEnter = e.key === "Enter" || e.key === " ";
419-
if (!isEnter) return;
418+
const isEnterOrSpace = e.key === "Enter" || e.key === " ";
419+
if (!isEnterOrSpace) return;
420420

421-
this.#applySuggestion(e);
421+
this.#onInputSuggestionEvent(e);
422422
}
423423

424-
#applySuggestion(e: Event | KeyboardEvent): void {
424+
#onInputSuggestionEvent(e: MouseEvent | KeyboardEvent): void {
425425
const { suggestion, submit } = this.#getSuggestion(e.target);
426426
if (!suggestion) return;
427427

428428
e.preventDefault();
429-
this.input.setInputValue(suggestion, { submit, focus: !submit });
429+
// Cmd/Ctrl + (event) = force submitting
430+
// Alt/Opt + (event) = force setting without submitting
431+
const shouldSubmit =
432+
e.metaKey || e.ctrlKey ? true : e.altKey ? false : submit;
433+
434+
this.input.setInputValue(suggestion, {
435+
submit: shouldSubmit,
436+
focus: !shouldSubmit,
437+
});
430438
}
431439

432440
#getSuggestion(x: EventTarget | null): {

0 commit comments

Comments
 (0)