Skip to content

Commit 60f3ef5

Browse files
committed
feat: ctrl+w to clear convo, fix: wrong hint on send btn about send shortcut
1 parent 5e549f1 commit 60f3ef5

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

src/client/components/ChatV2/ChatBox.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { BlueButton, GrayButton, OutlineButtonBlack } from './general/Buttons'
1515
import { useIsEmbedded } from '../../contexts/EmbeddedContext'
1616
import useCurrentUser from '../../hooks/useCurrentUser'
1717
import { SendPreferenceConfiguratorModal, ShiftEnterForNewline, ShiftEnterToSend } from './SendPreferenceConfigurator'
18+
import { useKeyboardCommands } from './keyboardCommands'
1819

1920
export const ChatBox = ({
2021
disabled,
@@ -77,6 +78,10 @@ export const ChatBox = ({
7778

7879
const { t } = useTranslation()
7980

81+
useKeyboardCommands({ resetChat: handleReset })
82+
83+
const isShiftEnterSend = user?.preferences?.sendShortcutMode === 'shift+enter'
84+
8085
const handleDeleteFile = () => {
8186
if (fileInputRef.current) {
8287
fileInputRef.current.value = ''
@@ -227,7 +232,7 @@ export const ChatBox = ({
227232
/>
228233
</IconButton>
229234
</Tooltip>
230-
<Tooltip title={t('chat:emptyConversation')} arrow placement="top">
235+
<Tooltip title={t('chat:emptyConversationTooltip')} arrow placement="top">
231236
<IconButton onClick={handleReset}>
232237
<RestartAltIcon />
233238
</IconButton>
@@ -238,7 +243,7 @@ export const ChatBox = ({
238243
)}
239244
</Box>
240245

241-
<Tooltip title={disabled ? t('chat:cancelResponse') : t('chat:shiftEnter')} arrow placement="top">
246+
<Tooltip title={disabled ? t('chat:cancelResponse') : isShiftEnterSend ? t('chat:shiftEnterSend') : t('chat:enterSend')} arrow placement="top">
242247
<IconButton type={disabled ? 'button' : 'submit'} ref={sendButtonRef}>
243248
{disabled ? <StopIcon /> : <Send />}
244249
</IconButton>
@@ -285,7 +290,7 @@ export const ChatBox = ({
285290
variant="body1"
286291
color="textSecondary"
287292
>
288-
{user?.preferences?.sendShortcutMode === 'enter' ? <ShiftEnterForNewline t={t} /> : <ShiftEnterToSend t={t} />}
293+
{isShiftEnterSend ? <ShiftEnterToSend t={t} /> : <ShiftEnterForNewline t={t} />}
289294
</Typography>
290295
)}
291296

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useEffect } from 'react'
2+
3+
export const useKeyboardCommands = ({ resetChat }: { resetChat: () => void }) => {
4+
useEffect(() => {
5+
const handleKeyDown = (event: KeyboardEvent) => {
6+
if (event.key === 'w' && event.ctrlKey) {
7+
resetChat()
8+
}
9+
}
10+
11+
window.addEventListener('keydown', handleKeyDown)
12+
13+
return () => {
14+
window.removeEventListener('keydown', handleKeyDown)
15+
}
16+
}, [resetChat])
17+
}

src/client/locales/en.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@
8484
"denySave": "The conversation may not be saved.",
8585
"toBeSaved": "The discussion will be saved anonymously",
8686
"emptyConversation": "Clear conversation",
87+
"emptyConversationTooltip": "Clear conversation (ctrl + W)",
8788
"emptyConfirm": "Are you sure you want to empty this conversation?",
8889
"settings": "Chat settings",
89-
"shiftEnter": "Or send on Shift + Enter",
90+
"shiftEnterSend": "Send (Shift + Enter)",
91+
"enterSend": "Send (Enter)",
92+
"chooseModelTooltip": "Choose model (ctrl + M)",
9093
"testUseInfo": "The new chat view is still in development and bugs are likely to occur",
9194
"searchTerms": "Searched for:",
9295
"readMore": "Read more",
@@ -321,4 +324,4 @@
321324
"ok": "Ok",
322325
"openConfigurator": "Keyboard shortcut for sending a message"
323326
}
324-
}
327+
}

src/client/locales/fi.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@
8484
"denySave": "Keskustelua ei saa tallentaa",
8585
"toBeSaved": "Keskustelu tallennetaan anonyymisti",
8686
"emptyConversation": "Tyhjennä keskustelu",
87+
"emptyConversationTooltip": "Tyhjennä keskustelu (ctrl + W)",
8788
"emptyConfirm": "Oletko varma että tahdot tyhjentää keskustelun?",
8889
"settings": "Keskustelun asetukset",
89-
"shiftEnter": "Tai lähetä Shift + Enterillä",
90+
"shiftEnterSend": "Lähetä (Shift + Enter)",
91+
"enterSend": "Lähetä (Enter)",
92+
"chooseModelTooltip": "Valitse malli (ctrl + M)",
9093
"testUseInfo": "Curren uusi chattinäkymä on vielä kehitysvaiheessa ja bugeja varmasti ilmenee",
9194
"searchTerms": "Hakusanat:",
9295
"readMore": "Lue lisää",
@@ -321,4 +324,4 @@
321324
"ok": "Ok",
322325
"openConfigurator": "Viestin lähetyksen näppäinyhdistelmä"
323326
}
324-
}
327+
}

0 commit comments

Comments
 (0)