Skip to content

Commit b55b732

Browse files
authored
feat: add configurable chat send shortcut (#1185)
1 parent 16645e2 commit b55b732

File tree

8 files changed

+74
-4
lines changed

8 files changed

+74
-4
lines changed

packages/web/public/locales/translation/en.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ chat:
1717
delete_link: Delete Link
1818
delete_link_message: You can stop sharing the conversation history by deleting the link.
1919
drop_files: Drop files here
20+
hint_cmd_enter: ⌘ + Enter to Submit
21+
hint_ctrl_enter: Ctrl + Enter to Submit
2022
history: Conversation History
2123
initialize: Initialize
2224
model_parameters: Model Parameters
@@ -782,6 +784,7 @@ setting:
782784
agent_enabled: Agent Enabled
783785
language: Language
784786
language_help: Change display language
787+
line_break_enter: Press Enter to create new line
785788
login_status: Login status
786789
rag_enabled: RAG (Amazon Kendra) Enabled
787790
rag_kb_enabled: RAG (Knowledge Base) Enabled

packages/web/public/locales/translation/ja.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ chat:
1515
delete_link: リンクの削除
1616
delete_link_message: リンクを削除することで、会話履歴の公開を停止できます。
1717
drop_files: ファイルをドロップしてください
18+
hint_cmd_enter: ⌘ + Enter で送信
19+
hint_ctrl_enter: Ctrl + Enter で送信
1820
history: 会話履歴
1921
initialize: 初期化
2022
model_parameters: モデルパラメータ
@@ -623,6 +625,7 @@ setting:
623625
agent_enabled: Agent 有効
624626
language: 言語設定
625627
language_help: 表示言語を変更できます
628+
line_break_enter: Enter で改行
626629
login_status: ログイン状態
627630
rag_enabled: RAG (Amazon Kendra) 有効
628631
rag_kb_enabled: RAG (Knowledge Base) 有効

packages/web/public/locales/translation/th.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ chat:
1515
delete_link: ลบลิงก์
1616
delete_link_message: คุณสามารถหยุดการแชร์ประวัติการสนทนาโดยการลบลิงก์
1717
drop_files: วางไฟล์ที่นี่
18+
hint_cmd_enter: ⌘ + Enter เพื่อส่ง
19+
hint_ctrl_enter: Ctrl + Enter เพื่อส่ง
1820
history: ประวัติการสนทนา
1921
initialize: เริ่มต้นใหม่
2022
model_parameters: พารามิเตอร์โมเดล
@@ -672,8 +674,15 @@ setting:
672674
agent_enabled: เปิดใช้งานตัวแทน
673675
language: ภาษา
674676
language_help: เปลี่ยนภาษาที่แสดง
677+
line_break_enter: กด Enter เพื่อขึ้นบรรทัดใหม่
678+
login_status: สถานะการเข้าสู่ระบบ
675679
rag_enabled: เปิดใช้งาน RAG (Amazon Kendra)
676680
rag_kb_enabled: เปิดใช้งาน RAG (Knowledge Base)
681+
show_email: แสดงอีเมล
682+
show_tools: แสดงเครื่องมือ
683+
show_use_case_builder: แสดง Use Case Builder
684+
stats: สถิติ
685+
typing_animation: แอนิเมชันการพิมพ์
677686
version: เวอร์ชัน
678687
version_help: อ้างอิงเวอร์ชันใน package.json ของ generative-ai-use-cases
679688
recent_updates: การอัปเดตล่าสุด

packages/web/public/locales/translation/vi.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ chat:
1515
delete_link: Xóa liên kết
1616
delete_link_message: Bằng cách xóa liên kết, bạn có thể ngừng công khai lịch sử cuộc trò chuyện.
1717
drop_files: Vui lòng thả file
18+
hint_cmd_enter: ⌘ + Enter để gửi
19+
hint_ctrl_enter: Ctrl + Enter để gửi
1820
history: Lịch sử cuộc trò chuyện
1921
initialize: Khởi tạo
2022
model_parameters: Tham số mô hình
@@ -650,6 +652,7 @@ setting:
650652
agent_enabled: Agent được bật
651653
language: Cài đặt ngôn ngữ
652654
language_help: Có thể thay đổi ngôn ngữ hiển thị
655+
line_break_enter: Nhấn Enter để xuống dòng
653656
login_status: Trạng thái đăng nhập
654657
rag_enabled: RAG (Amazon Kendra) được bật
655658
rag_kb_enabled: RAG (Knowledge Base) được bật

packages/web/src/components/InputChatContent.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import useFiles from '../hooks/useFiles';
1616
import FileCard from './FileCard';
1717
import { FileLimit } from 'generative-ai-use-cases';
1818
import { useTranslation } from 'react-i18next';
19+
import useUserSetting from '../hooks/useUserSetting';
1920

2021
type Props = {
2122
content: string;
@@ -49,6 +50,7 @@ type Props = {
4950

5051
const InputChatContent: React.FC<Props> = (props) => {
5152
const { t } = useTranslation();
53+
const { settingSubmitCmdOrCtrlEnter } = useUserSetting();
5254
const { pathname } = useLocation();
5355
const { loading: chatLoading, isEmpty } = useChat(pathname);
5456
const {
@@ -122,7 +124,11 @@ const InputChatContent: React.FC<Props> = (props) => {
122124
)}
123125
<div
124126
className={`relative flex items-end rounded-xl border border-black/10 bg-gray-100 shadow-[0_0_30px_1px] shadow-gray-400/40 ${
125-
props.disableMarginBottom ? '' : 'mb-7'
127+
props.disableMarginBottom
128+
? ''
129+
: settingSubmitCmdOrCtrlEnter
130+
? 'mb-2'
131+
: 'mb-7'
126132
}`}>
127133
<div className="flex grow flex-col">
128134
{props.fileUpload && uploadedFiles.length > 0 && (
@@ -246,6 +252,15 @@ const InputChatContent: React.FC<Props> = (props) => {
246252
</Button>
247253
)}
248254
</div>
255+
256+
{/* Show keyboard shortcut hint when cmd/ctrl+enter setting is enabled */}
257+
{settingSubmitCmdOrCtrlEnter && (
258+
<div className="mb-2 text-right text-xs text-gray-500">
259+
{navigator.platform.toLowerCase().includes('mac')
260+
? t('chat.hint_cmd_enter')
261+
: t('chat.hint_ctrl_enter')}
262+
</div>
263+
)}
249264
</div>
250265
);
251266
};

packages/web/src/components/Textarea.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useLayoutEffect, useRef } from 'react';
22
import RowItem, { RowItemProps } from './RowItem';
33
import Help from './Help';
44
import { useTranslation } from 'react-i18next';
5+
import useUserSetting from '../hooks/useUserSetting';
56

67
type Props = RowItemProps & {
78
value?: string;
@@ -24,6 +25,7 @@ const MAX_HEIGHT = 300;
2425

2526
const Textarea: React.FC<Props> = (props) => {
2627
const { t } = useTranslation();
28+
const { settingSubmitCmdOrCtrlEnter } = useUserSetting();
2729
const ref = useRef<HTMLTextAreaElement>(null);
2830
const maxHeight = props.maxHeight || MAX_HEIGHT;
2931

@@ -79,9 +81,28 @@ const Textarea: React.FC<Props> = (props) => {
7981
onKeyDown={(e) => {
8082
// keyCode is deprecated, but used for some browsers to handle IME input
8183
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
82-
if (props.onEnter && e.key === 'Enter' && !e.shiftKey) {
83-
e.preventDefault();
84-
props.onEnter();
84+
85+
if (props.onEnter) {
86+
if (settingSubmitCmdOrCtrlEnter) {
87+
// When line break mode is enabled, enter key creates new line and cmd/ctrl+enter sends message
88+
if (navigator.platform.toLowerCase().includes('mac')) {
89+
if (e.key === 'Enter' && e.metaKey) {
90+
e.preventDefault();
91+
props.onEnter();
92+
}
93+
} else {
94+
if (e.key === 'Enter' && e.ctrlKey) {
95+
e.preventDefault();
96+
props.onEnter();
97+
}
98+
}
99+
} else {
100+
// Default behavior: send with enter (not cmd/ctrl+enter)
101+
if (e.key === 'Enter' && !e.shiftKey) {
102+
e.preventDefault();
103+
props.onEnter();
104+
}
105+
}
85106
}
86107
}}
87108
onChange={(e) => {

packages/web/src/hooks/useUserSetting.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import useLocalStorageBoolean from './useLocalStorageBoolean';
22

33
const useUserSetting = () => {
4+
const [settingSubmitCmdOrCtrlEnter, setSettingSubmitCmdOrCtrlEnter] =
5+
useLocalStorageBoolean('submitCmdOrCtrlEnter', false);
46
const [settingTypingAnimation, setSettingTypingAnimation] =
57
useLocalStorageBoolean('typingAnimation', true);
68
const [settingShowUseCaseBuilder, setSettingShowUseCaseBuilder] =
@@ -15,6 +17,8 @@ const useUserSetting = () => {
1517
);
1618

1719
return {
20+
settingSubmitCmdOrCtrlEnter,
21+
setSettingSubmitCmdOrCtrlEnter,
1822
settingTypingAnimation,
1923
setSettingTypingAnimation,
2024
settingShowUseCaseBuilder,

packages/web/src/pages/Setting.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const Setting = () => {
5757
const hasUpdate = getHasUpdate();
5858
const closedPullRequests = getClosedPullRequests();
5959
const {
60+
settingSubmitCmdOrCtrlEnter,
61+
setSettingSubmitCmdOrCtrlEnter,
6062
settingTypingAnimation,
6163
setSettingTypingAnimation,
6264
settingShowUseCaseBuilder,
@@ -117,6 +119,16 @@ const Setting = () => {
117119
top={true}
118120
/>
119121

122+
<SettingItem
123+
name={t('setting.items.line_break_enter')}
124+
value={
125+
<Switch
126+
checked={settingSubmitCmdOrCtrlEnter}
127+
label=""
128+
onSwitch={setSettingSubmitCmdOrCtrlEnter}
129+
/>
130+
}></SettingItem>
131+
120132
<SettingItem
121133
name={t('setting.items.typing_animation')}
122134
value={

0 commit comments

Comments
 (0)