feat: option for enterToSubmit / shiftEnterToSubmit

Fixes #88
This commit is contained in:
Jing Hua 2023-03-30 16:01:01 +08:00
parent 4e0b31cb1b
commit 78bf777365
16 changed files with 78 additions and 17 deletions

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "Ny mappe", "newFolder": "Ny mappe",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "New Folder", "newFolder": "New Folder",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "Nueva Carpeta", "newFolder": "Nueva Carpeta",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "Nouveau Dossier", "newFolder": "Nouveau Dossier",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "新しいフォルダー", "newFolder": "新しいフォルダー",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "Folder Baru", "newFolder": "Folder Baru",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "Ny mappe", "newFolder": "Ny mappe",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "Ny mapp", "newFolder": "Ny mapp",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "新文件夹", "newFolder": "新文件夹",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "新資料夾", "newFolder": "新資料夾",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -35,5 +35,6 @@
}, },
"newFolder": "新資料夾", "newFolder": "新資料夾",
"cloneChat": "Clone Chat", "cloneChat": "Clone Chat",
"cloned": "Cloned" "cloned": "Cloned",
"enterToSubmit": "Enter to submit"
} }

View file

@ -342,12 +342,20 @@ const EditView = ({
}; };
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if ((e.ctrlKey || e.shiftKey) && e.key === 'Enter') { if (e.key === 'Enter') {
e.preventDefault(); const enterToSubmit = useStore.getState().enterToSubmit;
if (sticky) { if (sticky) {
if (
(enterToSubmit && !e.shiftKey) ||
(!enterToSubmit && (e.ctrlKey || e.shiftKey))
) {
e.preventDefault();
handleSaveAndSubmit(); handleSaveAndSubmit();
resetTextAreaHeight(); resetTextAreaHeight();
} else handleSave(); }
} else if (e.ctrlKey || e.shiftKey) {
handleSave();
}
} }
}; };

View file

@ -0,0 +1,28 @@
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import useStore from '@store/store';
import Toggle from '@components/Toggle';
const EnterToSubmitToggle = () => {
const { t } = useTranslation();
const setEnterToSubmit = useStore((state) => state.setEnterToSubmit);
const [isChecked, setIsChecked] = useState<boolean>(
useStore.getState().enterToSubmit
);
useEffect(() => {
setEnterToSubmit(isChecked);
}, [isChecked]);
return (
<Toggle
label={t('enterToSubmit') as string}
isChecked={isChecked}
setIsChecked={setIsChecked}
/>
);
};
export default EnterToSubmitToggle;

View file

@ -9,6 +9,7 @@ import LanguageSelector from '@components/LanguageSelector';
import AutoTitleToggle from './AutoTitleToggle'; import AutoTitleToggle from './AutoTitleToggle';
import PromptLibraryMenu from '@components/PromptLibraryMenu'; import PromptLibraryMenu from '@components/PromptLibraryMenu';
import ChatConfigMenu from '@components/ChatConfigMenu'; import ChatConfigMenu from '@components/ChatConfigMenu';
import EnterToSubmitToggle from './EnterToSubmitToggle';
const SettingsMenu = () => { const SettingsMenu = () => {
const { t } = useTranslation(); const { t } = useTranslation();
@ -38,7 +39,10 @@ const SettingsMenu = () => {
<div className='p-6 border-b border-gray-200 dark:border-gray-600 flex flex-col items-center gap-4'> <div className='p-6 border-b border-gray-200 dark:border-gray-600 flex flex-col items-center gap-4'>
<LanguageSelector /> <LanguageSelector />
<ThemeSwitcher /> <ThemeSwitcher />
<div className='flex flex-col gap-3'>
<AutoTitleToggle /> <AutoTitleToggle />
<EnterToSubmitToggle />
</div>
<PromptLibraryMenu /> <PromptLibraryMenu />
<ChatConfigMenu /> <ChatConfigMenu />
</div> </div>

View file

@ -11,6 +11,7 @@ export interface ConfigSlice {
defaultChatConfig: ConfigInterface; defaultChatConfig: ConfigInterface;
defaultSystemMessage: string; defaultSystemMessage: string;
hideSideMenu: boolean; hideSideMenu: boolean;
enterToSubmit: boolean;
setOpenConfig: (openConfig: boolean) => void; setOpenConfig: (openConfig: boolean) => void;
setTheme: (theme: Theme) => void; setTheme: (theme: Theme) => void;
setAutoTitle: (autoTitle: boolean) => void; setAutoTitle: (autoTitle: boolean) => void;
@ -18,6 +19,7 @@ export interface ConfigSlice {
setDefaultSystemMessage: (defaultSystemMessage: string) => void; setDefaultSystemMessage: (defaultSystemMessage: string) => void;
setHideMenuOptions: (hideMenuOptions: boolean) => void; setHideMenuOptions: (hideMenuOptions: boolean) => void;
setHideSideMenu: (hideSideMenu: boolean) => void; setHideSideMenu: (hideSideMenu: boolean) => void;
setEnterToSubmit: (enterToSubmit: boolean) => void;
} }
export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({ export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({
@ -26,6 +28,7 @@ export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({
hideMenuOptions: false, hideMenuOptions: false,
hideSideMenu: false, hideSideMenu: false,
autoTitle: false, autoTitle: false,
enterToSubmit: true,
defaultChatConfig: _defaultChatConfig, defaultChatConfig: _defaultChatConfig,
defaultSystemMessage: _defaultSystemMessage, defaultSystemMessage: _defaultSystemMessage,
setOpenConfig: (openConfig: boolean) => { setOpenConfig: (openConfig: boolean) => {
@ -70,4 +73,10 @@ export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({
hideSideMenu: hideSideMenu, hideSideMenu: hideSideMenu,
})); }));
}, },
setEnterToSubmit: (enterToSubmit: boolean) => {
set((prev: ConfigSlice) => ({
...prev,
enterToSubmit: enterToSubmit,
}));
},
}); });

View file

@ -61,6 +61,7 @@ const useStore = create<StoreState>()(
hideSideMenu: state.hideSideMenu, hideSideMenu: state.hideSideMenu,
foldersName: state.foldersName, foldersName: state.foldersName,
foldersExpanded: state.foldersExpanded, foldersExpanded: state.foldersExpanded,
enterToSubmit: state.enterToSubmit,
}), }),
version: 7, version: 7,
migrate: (persistedState, version) => { migrate: (persistedState, version) => {