Skip to content
Closed
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
29 changes: 26 additions & 3 deletions webview-ui/src/components/chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0

const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryView }: ChatViewProps) => {
const { t } = useAppTranslation()
const modeShortcutText = `${isMac ? "⌘" : "Ctrl"} + . ${t("chat:forNextMode")}`
const modeShortcutText = `${isMac ? "⌘" : "Ctrl"} + . next or / prev mode` // Updated shortcut hint format
Copy link
Contributor

Choose a reason for hiding this comment

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

The shortcut hint text is now hard-coded as ${isMac ? "⌘" : "Ctrl"} + . next or / prev mode. For consistency and internationalization, consider using the translation function (t) instead of hard-coding the string.

const {
version,
clineMessages: messages,
Expand Down Expand Up @@ -1130,16 +1130,39 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
})
}, [mode, setMode, customModes])

// Function to switch to the previous mode
const switchToPreviousMode = useCallback(() => {
const allModes = getAllModes(customModes)
const currentModeIndex = allModes.findIndex((m) => m.slug === mode)
if (currentModeIndex === -1) return // Should not happen

// Calculate previous index with wrap-around
const previousModeIndex = (currentModeIndex - 1 + allModes.length) % allModes.length
const previousMode = allModes[previousModeIndex]

// Update local state and notify extension to sync mode change
setMode(previousMode.slug)
vscode.postMessage({
type: "mode",
text: previousMode.slug,
})
// Consider adding playSound("progress_loop") here if desired for consistency
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a commented suggestion to add playSound('progress_loop') in switchToPreviousMode. For clarity, either remove this comment or implement the functionality consistently if it is desired.

Suggested change
// Consider adding playSound("progress_loop") here if desired for consistency

}, [mode, setMode, customModes])

// Add keyboard event handler
const handleKeyDown = useCallback(
(event: KeyboardEvent) => {
// Check for Command + . (period)
// Check for Command + . (period) for next mode
if ((event.metaKey || event.ctrlKey) && event.key === ".") {
event.preventDefault() // Prevent default browser behavior
switchToNextMode()
// Check for Command + / (slash) for previous mode
} else if ((event.metaKey || event.ctrlKey) && event.key === "/") {
event.preventDefault() // Prevent default browser behavior
switchToPreviousMode()
}
},
[switchToNextMode],
[switchToNextMode, switchToPreviousMode], // Added switchToPreviousMode dependency
)

// Add event listener
Expand Down