Skip to content

Commit

Permalink
Enter to send: renamed to Enter is Newline
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Oct 31, 2023
1 parent 53533d0 commit e3d2327
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
9 changes: 3 additions & 6 deletions src/apps/chat/components/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ export function Composer(props: {
// external state
const theme = useTheme();
const [chatModeId, setChatModeId] = useChatModeStore(state => [state.chatModeId, state.setChatModeId], shallow);
const { enterToSend, experimentalLabs } = useUIPreferencesStore(state => ({
enterToSend: state.enterToSend,
experimentalLabs: state.experimentalLabs,
}), shallow);
const [enterIsNewline, experimentalLabs] = useUIPreferencesStore(state => [state.enterIsNewline, state.experimentalLabs], shallow);
const { startupText, setStartupText } = useComposerStore();
const { assistantTyping, systemPurposeId, tokenCount: conversationTokenCount, stopTyping } = useChatStore(state => {
const conversation = state.conversations.find(conversation => conversation.id === props.conversationId);
Expand Down Expand Up @@ -211,7 +208,7 @@ export function Composer(props: {
const handleTextareaKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
const shiftOrAlt = e.shiftKey || e.altKey;
if (enterToSend ? !shiftOrAlt : shiftOrAlt) {
if (enterIsNewline ? shiftOrAlt : !shiftOrAlt) {
if (!assistantTyping)
handleSendClicked();
e.preventDefault();
Expand Down Expand Up @@ -479,7 +476,7 @@ export function Composer(props: {
onPasteCapture={handleTextareaCtrlV}
slotProps={{
textarea: {
enterKeyHint: enterToSend ? 'send' : 'enter',
enterKeyHint: enterIsNewline ? 'enter' : 'send',
sx: {
...(isSpeechEnabled ? { pr: { md: 5 } } : {}),
mb: 0.5,
Expand Down
12 changes: 6 additions & 6 deletions src/apps/settings-modal/UISettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export function UISettings() {
const {
centerMode, setCenterMode,
doubleClickToEdit, setDoubleClickToEdit,
enterToSend, setEnterToSend,
enterIsNewline, setEnterIsNewline,
experimentalLabs, setExperimentalLabs,
renderMarkdown, setRenderMarkdown,
showPurposeFinder, setShowPurposeFinder,
zenMode, setZenMode,
} = useUIPreferencesStore(state => ({
centerMode: state.centerMode, setCenterMode: state.setCenterMode,
doubleClickToEdit: state.doubleClickToEdit, setDoubleClickToEdit: state.setDoubleClickToEdit,
enterToSend: state.enterToSend, setEnterToSend: state.setEnterToSend,
enterIsNewline: state.enterIsNewline, setEnterIsNewline: state.setEnterIsNewline,
experimentalLabs: state.experimentalLabs, setExperimentalLabs: state.setExperimentalLabs,
renderMarkdown: state.renderMarkdown, setRenderMarkdown: state.setRenderMarkdown,
showPurposeFinder: state.showPurposeFinder, setShowPurposeFinder: state.setShowPurposeFinder,
Expand All @@ -41,7 +41,7 @@ export function UISettings() {

const handleCenterModeChange = (event: React.ChangeEvent<HTMLInputElement>) => setCenterMode(event.target.value as 'narrow' | 'wide' | 'full' || 'wide');

const handleEnterToSendChange = (event: React.ChangeEvent<HTMLInputElement>) => setEnterToSend(event.target.checked);
const handleEnterIsNewlineChange = (event: React.ChangeEvent<HTMLInputElement>) => setEnterIsNewline(!event.target.checked);

const handleDoubleClickToEditChange = (event: React.ChangeEvent<HTMLInputElement>) => setDoubleClickToEdit(event.target.checked);

Expand Down Expand Up @@ -72,10 +72,10 @@ export function UISettings() {
<FormControl orientation='horizontal' sx={{ justifyContent: 'space-between' }}>
<Box>
<FormLabel>Enter to send</FormLabel>
<FormHelperText>{enterToSend ? <>Sends message<TelegramIcon /></> : 'New line'}</FormHelperText>
<FormHelperText>{enterIsNewline ? 'New line' : <>Sends message<TelegramIcon /></>}</FormHelperText>
</Box>
<Switch checked={enterToSend} onChange={handleEnterToSendChange}
endDecorator={enterToSend ? 'On' : 'Off'}
<Switch checked={!enterIsNewline} onChange={handleEnterIsNewlineChange}
endDecorator={enterIsNewline ? 'Off' : 'On'}
slotProps={{ endDecorator: { sx: { minWidth: 26 } } }} />
</FormControl>

Expand Down
11 changes: 6 additions & 5 deletions src/common/components/InlineTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { useUIPreferencesStore } from '~/common/state/store-ui';
export function InlineTextarea(props: { initialText: string, onEdit: (text: string) => void, sx?: SxProps }) {

const [text, setText] = React.useState(props.initialText);
const enterToSend = useUIPreferencesStore(state => state.enterToSend);
const enterIsNewline = useUIPreferencesStore(state => state.enterIsNewline);

const handleEditTextChanged = (e: React.ChangeEvent<HTMLTextAreaElement>) => setText(e.target.value);

const handleEditKeyPressed = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
const handleEditKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter') {
const shiftOrAlt = e.shiftKey || e.altKey;
if (enterToSend ? !shiftOrAlt : shiftOrAlt) {
if (enterIsNewline ? shiftOrAlt : !shiftOrAlt) {
e.preventDefault();
props.onEdit(text);
}
Expand All @@ -28,10 +28,11 @@ export function InlineTextarea(props: { initialText: string, onEdit: (text: stri
return (
<Textarea
variant='soft' color='warning' autoFocus minRows={1}
value={text} onChange={handleEditTextChanged} onKeyDown={handleEditKeyPressed} onBlur={handleEditBlur}
value={text} onChange={handleEditTextChanged}
onKeyDown={handleEditKeyDown} onBlur={handleEditBlur}
slotProps={{
textarea: {
enterKeyHint: enterToSend ? 'done' : 'enter',
enterKeyHint: enterIsNewline ? 'enter' : 'done',
},
}}
sx={props.sx}
Expand Down
20 changes: 16 additions & 4 deletions src/common/state/store-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ interface UIPreferencesStore {
doubleClickToEdit: boolean;
setDoubleClickToEdit: (doubleClickToEdit: boolean) => void;

enterToSend: boolean;
setEnterToSend: (enterToSend: boolean) => void;
enterIsNewline: boolean;
setEnterIsNewline: (enterIsNewline: boolean) => void;

experimentalLabs: boolean;
setExperimentalLabs: (experimentalLabs: boolean) => void;
Expand Down Expand Up @@ -125,8 +125,8 @@ export const useUIPreferencesStore = create<UIPreferencesStore>()(
doubleClickToEdit: true,
setDoubleClickToEdit: (doubleClickToEdit: boolean) => set({ doubleClickToEdit }),

enterToSend: true,
setEnterToSend: (enterToSend: boolean) => set({ enterToSend }),
enterIsNewline: false,
setEnterIsNewline: (enterIsNewline: boolean) => set({ enterIsNewline }),

experimentalLabs: false,
setExperimentalLabs: (experimentalLabs: boolean) => set({ experimentalLabs }),
Expand All @@ -146,6 +146,18 @@ export const useUIPreferencesStore = create<UIPreferencesStore>()(
}),
{
name: 'app-ui',

/* versioning:
* 1: rename 'enterToSend' to 'enterIsNewline' (flip the meaning)
*/
version: 1,

migrate: (state: any, fromVersion: number): UIPreferencesStore => {
// 0 -> 1: rename 'enterToSend' to 'enterIsNewline' (flip the meaning)
if (state && fromVersion === 0)
state.enterIsNewline = state['enterToSend'] === false;
return state;
},
},
),
);

1 comment on commit e3d2327

@vercel
Copy link

@vercel vercel bot commented on e3d2327 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

big-agi – ./

get.big-agi.com
big-agi-git-main-enricoros.vercel.app
big-agi-enricoros.vercel.app

Please sign in to comment.