Skip to content

feat: add configurable chat send shortcut #1185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/web/public/locales/translation/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ chat:
delete_link: Delete Link
delete_link_message: You can stop sharing the conversation history by deleting the link.
drop_files: Drop files here
hint_cmd_enter: ⌘ + Enter to Submit
hint_ctrl_enter: Ctrl + Enter to Submit
history: Conversation History
initialize: Initialize
model_parameters: Model Parameters
Expand Down Expand Up @@ -781,6 +783,7 @@ setting:
show_tools: Show Tools
show_use_case_builder: Show Use Case Builder
stats: Statistics
submit_cmd_or_ctrl_enter: ⌘ (ctrl) + Enter to Submit
typing_animation: Typing Animation
version: Version
version_help: Referencing the version in package.json of generative-ai-use-cases
Expand Down
3 changes: 3 additions & 0 deletions packages/web/public/locales/translation/ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ chat:
delete_link: リンクの削除
delete_link_message: リンクを削除することで、会話履歴の公開を停止できます。
drop_files: ファイルをドロップしてください
hint_cmd_enter: ⌘ + Enter で送信
hint_ctrl_enter: Ctrl + Enter で送信
history: 会話履歴
initialize: 初期化
model_parameters: モデルパラメータ
Expand Down Expand Up @@ -622,6 +624,7 @@ setting:
show_tools: ツールの表示
show_use_case_builder: ユースケースビルダーの表示
stats: 利用統計
submit_cmd_or_ctrl_enter: ⌘ (ctrl) + Enter で送信
typing_animation: タイピングアニメーション
version: バージョン
version_help: generative-ai-use-cases の package.json の version を参照しています
Expand Down
9 changes: 9 additions & 0 deletions packages/web/public/locales/translation/th.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ chat:
delete_link: ลบลิงก์
delete_link_message: คุณสามารถหยุดการแชร์ประวัติการสนทนาโดยการลบลิงก์
drop_files: วางไฟล์ที่นี่
hint_cmd_enter: ⌘ + Enter เพื่อส่ง
hint_ctrl_enter: Ctrl + Enter เพื่อส่ง
history: ประวัติการสนทนา
initialize: เริ่มต้นใหม่
model_parameters: พารามิเตอร์โมเดล
Expand Down Expand Up @@ -664,8 +666,15 @@ setting:
agent_enabled: เปิดใช้งานตัวแทน
language: ภาษา
language_help: เปลี่ยนภาษาที่แสดง
login_status: สถานะการเข้าสู่ระบบ
rag_enabled: เปิดใช้งาน RAG (Amazon Kendra)
rag_kb_enabled: เปิดใช้งาน RAG (Knowledge Base)
show_email: แสดงอีเมล
show_tools: แสดงเครื่องมือ
show_use_case_builder: แสดง Use Case Builder
stats: สถิติ
submit_cmd_or_ctrl_enter: ⌘ (ctrl) + Enter เพื่อส่ง
typing_animation: แอนิเมชันการพิมพ์
version: เวอร์ชัน
version_help: อ้างอิงเวอร์ชันใน package.json ของ generative-ai-use-cases
recent_updates: การอัปเดตล่าสุด
Expand Down
3 changes: 3 additions & 0 deletions packages/web/public/locales/translation/vi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ chat:
delete_link: Xóa liên kết
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.
drop_files: Vui lòng thả file
hint_cmd_enter: ⌘ + Enter để gửi
hint_ctrl_enter: Ctrl + Enter để gửi
history: Lịch sử cuộc trò chuyện
initialize: Khởi tạo
model_parameters: Tham số mô hình
Expand Down Expand Up @@ -620,6 +622,7 @@ setting:
rag_kb_enabled: RAG (Knowledge Base) được bật
show_tools: Hiển thị công cụ
show_use_case_builder: Hiển thị Use Case Builder
submit_cmd_or_ctrl_enter: ⌘ (ctrl) + Enter để gửi
typing_animation: Hiệu ứng đánh máy
version: Phiên bản
version_help: Tham chiếu đến version trong package.json của generative-ai-use-cases
Expand Down
17 changes: 16 additions & 1 deletion packages/web/src/components/InputChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useFiles from '../hooks/useFiles';
import FileCard from './FileCard';
import { FileLimit } from 'generative-ai-use-cases';
import { useTranslation } from 'react-i18next';
import useUserSetting from '../hooks/useUserSetting';

type Props = {
content: string;
Expand Down Expand Up @@ -49,6 +50,7 @@ type Props = {

const InputChatContent: React.FC<Props> = (props) => {
const { t } = useTranslation();
const { settingSubmitCmdOrCtrlEnter } = useUserSetting();
const { pathname } = useLocation();
const { loading: chatLoading, isEmpty } = useChat(pathname);
const {
Expand Down Expand Up @@ -122,7 +124,11 @@ const InputChatContent: React.FC<Props> = (props) => {
)}
<div
className={`relative flex items-end rounded-xl border border-black/10 bg-gray-100 shadow-[0_0_30px_1px] shadow-gray-400/40 ${
props.disableMarginBottom ? '' : 'mb-7'
props.disableMarginBottom
? ''
: settingSubmitCmdOrCtrlEnter
? 'mb-2'
: 'mb-7'
}`}>
<div className="flex grow flex-col">
{props.fileUpload && uploadedFiles.length > 0 && (
Expand Down Expand Up @@ -246,6 +252,15 @@ const InputChatContent: React.FC<Props> = (props) => {
</Button>
)}
</div>

{/* Show keyboard shortcut hint when cmd/ctrl+enter setting is enabled */}
{settingSubmitCmdOrCtrlEnter && (
<div className="mb-2 text-right text-xs text-gray-500">
{navigator.platform.toLowerCase().includes('mac')
? t('chat.hint_cmd_enter')
: t('chat.hint_ctrl_enter')}
</div>
)}
</div>
);
};
Expand Down
20 changes: 17 additions & 3 deletions packages/web/src/components/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useLayoutEffect, useRef } from 'react';
import RowItem, { RowItemProps } from './RowItem';
import Help from './Help';
import { useTranslation } from 'react-i18next';
import useUserSetting from '../hooks/useUserSetting';

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

const Textarea: React.FC<Props> = (props) => {
const { t } = useTranslation();
const { settingSubmitCmdOrCtrlEnter } = useUserSetting();
const ref = useRef<HTMLTextAreaElement>(null);
const maxHeight = props.maxHeight || MAX_HEIGHT;

Expand Down Expand Up @@ -79,9 +81,21 @@ const Textarea: React.FC<Props> = (props) => {
onKeyDown={(e) => {
// keyCode is deprecated, but used for some browsers to handle IME input
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
if (props.onEnter && e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
props.onEnter();

if (props.onEnter) {
if (settingSubmitCmdOrCtrlEnter) {
// When cmd/ctrl+enter setting is enabled, send with cmd/ctrl+enter
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
props.onEnter();
}
} else {
// Default behavior: send with enter (not shift+enter)
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
props.onEnter();
}
}
}
}}
onChange={(e) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/web/src/hooks/useUserSetting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import useLocalStorageBoolean from './useLocalStorageBoolean';

const useUserSetting = () => {
const [settingSubmitCmdOrCtrlEnter, setSettingSubmitCmdOrCtrlEnter] =
useLocalStorageBoolean('submitCmdOrCtrlEnter', false);
const [settingTypingAnimation, setSettingTypingAnimation] =
useLocalStorageBoolean('typingAnimation', true);
const [settingShowUseCaseBuilder, setSettingShowUseCaseBuilder] =
Expand All @@ -15,6 +17,8 @@ const useUserSetting = () => {
);

return {
settingSubmitCmdOrCtrlEnter,
setSettingSubmitCmdOrCtrlEnter,
settingTypingAnimation,
setSettingTypingAnimation,
settingShowUseCaseBuilder,
Expand Down
12 changes: 12 additions & 0 deletions packages/web/src/pages/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const Setting = () => {
const hasUpdate = getHasUpdate();
const closedPullRequests = getClosedPullRequests();
const {
settingSubmitCmdOrCtrlEnter,
setSettingSubmitCmdOrCtrlEnter,
settingTypingAnimation,
setSettingTypingAnimation,
settingShowUseCaseBuilder,
Expand Down Expand Up @@ -117,6 +119,16 @@ const Setting = () => {
top={true}
/>

<SettingItem
name={t('setting.items.submit_cmd_or_ctrl_enter')}
value={
<Switch
checked={settingSubmitCmdOrCtrlEnter}
label=""
onSwitch={setSettingSubmitCmdOrCtrlEnter}
/>
}></SettingItem>

<SettingItem
name={t('setting.items.typing_animation')}
value={
Expand Down