Skip to content

Commit 8f5c130

Browse files
authored
feat: add Cmd+Shift+. keyboard shortcut for previous mode switching (#5695)
* feat: add Cmd+Shift+. keyboard shortcut for previous mode switching - Add switchToPreviousMode function that cycles backwards through modes array - Update handleKeyDown to detect Cmd+Shift+. keyboard combination - Update modeShortcutText to display both next and previous mode shortcuts - Add forPreviousMode translation key to all 18 language files - Implements backwards mode cycling using modulo arithmetic for proper array wrapping Fixes #5692 * fix: correct keyboard shortcut detection for Cmd+Shift+. (previous mode) When Shift is pressed with the period key, event.key becomes ">" instead of ".". Fixed line 1576 to check for event.key === ">" for proper Cmd+Shift+. detection. Fixes keyboard shortcut issue reported in PR comment. * fix: use event.code for cross-platform keyboard shortcut compatibility - Replace event.key checks with event.code === "Period" for both shortcuts - Fixes keyboard layout compatibility issue where Shift+Period produces different characters on non-US layouts - Consolidates both shortcuts into a single conditional block for better maintainability - Addresses feedback from @daniel-lxs in PR #5695
1 parent 88c4261 commit 8f5c130

File tree

19 files changed

+40
-5
lines changed

19 files changed

+40
-5
lines changed

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
7979
})
8080
const { t } = useAppTranslation()
8181
const { t: tSettings } = useTranslation("settings")
82-
const modeShortcutText = `${isMac ? "⌘" : "Ctrl"} + . ${t("chat:forNextMode")}`
82+
const modeShortcutText = `${isMac ? "⌘" : "Ctrl"} + . ${t("chat:forNextMode")}, ${isMac ? "⌘" : "Ctrl"} + Shift + . ${t("chat:forPreviousMode")}`
8383
const {
8484
clineMessages: messages,
8585
currentTaskItem,
@@ -1555,16 +1555,33 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
15551555
switchToMode(allModes[nextModeIndex].slug)
15561556
}, [mode, customModes, switchToMode])
15571557

1558+
// Function to handle switching to previous mode
1559+
const switchToPreviousMode = useCallback(() => {
1560+
const allModes = getAllModes(customModes)
1561+
const currentModeIndex = allModes.findIndex((m) => m.slug === mode)
1562+
const previousModeIndex = (currentModeIndex - 1 + allModes.length) % allModes.length
1563+
// Update local state and notify extension to sync mode change
1564+
switchToMode(allModes[previousModeIndex].slug)
1565+
}, [mode, customModes, switchToMode])
1566+
15581567
// Add keyboard event handler
15591568
const handleKeyDown = useCallback(
15601569
(event: KeyboardEvent) => {
1561-
// Check for Command + . (period)
1562-
if ((event.metaKey || event.ctrlKey) && event.key === ".") {
1570+
// Check for Command/Ctrl + Period (with or without Shift)
1571+
// Using event.code for better cross-platform compatibility
1572+
if ((event.metaKey || event.ctrlKey) && event.code === "Period") {
15631573
event.preventDefault() // Prevent default browser behavior
1564-
switchToNextMode()
1574+
1575+
if (event.shiftKey) {
1576+
// Shift + Period = Previous mode
1577+
switchToPreviousMode()
1578+
} else {
1579+
// Just Period = Next mode
1580+
switchToNextMode()
1581+
}
15651582
}
15661583
},
1567-
[switchToNextMode],
1584+
[switchToNextMode, switchToPreviousMode],
15681585
)
15691586

15701587
// Add event listener

webview-ui/src/i18n/locales/ca/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"separator": "Separador",
124124
"edit": "Edita...",
125125
"forNextMode": "per al següent mode",
126+
"forPreviousMode": "per al mode anterior",
126127
"error": "Error",
127128
"diffError": {
128129
"title": "Edició fallida"

webview-ui/src/i18n/locales/de/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"separator": "Trennlinie",
124124
"edit": "Bearbeiten...",
125125
"forNextMode": "für nächsten Modus",
126+
"forPreviousMode": "für vorherigen Modus",
126127
"error": "Fehler",
127128
"diffError": {
128129
"title": "Bearbeitung fehlgeschlagen"

webview-ui/src/i18n/locales/en/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"separator": "Separator",
132132
"edit": "Edit...",
133133
"forNextMode": "for next mode",
134+
"forPreviousMode": "for previous mode",
134135
"apiRequest": {
135136
"title": "API Request",
136137
"failed": "API Request Failed",

webview-ui/src/i18n/locales/es/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"separator": "Separador",
124124
"edit": "Editar...",
125125
"forNextMode": "para el siguiente modo",
126+
"forPreviousMode": "para el modo anterior",
126127
"error": "Error",
127128
"diffError": {
128129
"title": "Edición fallida"

webview-ui/src/i18n/locales/fr/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"separator": "Séparateur",
124124
"edit": "Éditer...",
125125
"forNextMode": "pour le prochain mode",
126+
"forPreviousMode": "pour le mode précédent",
126127
"error": "Erreur",
127128
"diffError": {
128129
"title": "Modification échouée"

webview-ui/src/i18n/locales/hi/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"separator": "विभाजक",
124124
"edit": "संपादित करें...",
125125
"forNextMode": "अगले मोड के लिए",
126+
"forPreviousMode": "पिछले मोड के लिए",
126127
"error": "त्रुटि",
127128
"diffError": {
128129
"title": "संपादन असफल"

webview-ui/src/i18n/locales/id/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"separator": "Pemisah",
138138
"edit": "Edit...",
139139
"forNextMode": "untuk mode selanjutnya",
140+
"forPreviousMode": "untuk mode sebelumnya",
140141
"apiRequest": {
141142
"title": "Permintaan API",
142143
"failed": "Permintaan API Gagal",

webview-ui/src/i18n/locales/it/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"separator": "Separatore",
124124
"edit": "Modifica...",
125125
"forNextMode": "per la prossima modalità",
126+
"forPreviousMode": "per la modalità precedente",
126127
"instructions": {
127128
"wantsToFetch": "Roo vuole recuperare istruzioni dettagliate per aiutare con l'attività corrente"
128129
},

webview-ui/src/i18n/locales/ja/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"separator": "区切り",
124124
"edit": "編集...",
125125
"forNextMode": "次のモード用",
126+
"forPreviousMode": "前のモード用",
126127
"error": "エラー",
127128
"diffError": {
128129
"title": "編集に失敗しました"

0 commit comments

Comments
 (0)