Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions webview-ui/src/components/chat/AutoApproveDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Popover, PopoverContent, PopoverTrigger, StandardTooltip, ToggleSwitch
import { AutoApproveSetting, autoApproveSettingsConfig } from "../settings/AutoApproveToggle"
import { useAutoApprovalToggles } from "@/hooks/useAutoApprovalToggles"
import { useAutoApprovalState } from "@/hooks/useAutoApprovalState"
import { ShortcutHint } from "./ShortcutHint"

interface AutoApproveDropdownProps {
disabled?: boolean
Expand Down Expand Up @@ -222,6 +223,7 @@ export const AutoApproveDropdown = ({ disabled = false, triggerClassName = "" }:
<p className="m-0 text-xs text-vscode-descriptionForeground">
{t("chat:autoApprove.description")}
</p>
<ShortcutHint translationKey={"chat:autoApprove.toggleShortcut"} />
</div>
<div className="grid grid-cols-1 min-[340px]:grid-cols-2 gap-x-2 gap-y-2 p-3">
{settingsArray.map(({ key, labelKey, descriptionKey, icon }) => {
Expand Down
43 changes: 43 additions & 0 deletions webview-ui/src/components/chat/ShortcutHint.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from "react"
import { Trans } from "react-i18next"

import { useAppTranslation } from "@/i18n/TranslationContext"
import { usePlatform } from "@/hooks/usePlatform"

interface ShortcutHintProps {
translationKey: string
}

export const ShortcutHint: React.FC<ShortcutHintProps> = ({ translationKey }) => {
const { t } = useAppTranslation()
Copy link
Author

Choose a reason for hiding this comment

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

The useAppTranslation hook is imported but never used. The component only uses the Trans component directly with the translationKey prop. Consider removing this unused import to keep the code clean.

const platform = usePlatform()

const getShortcut = () => {
switch (platform) {
case "mac":
return "⌘⌥A"
case "windows":
case "linux":
return "Ctrl+Alt+A"
default:
return ""
}
}

const shortcut = getShortcut()

if (!shortcut) {
return null
}

return (
<p className="m-0 text-xs text-vscode-descriptionForeground">
<Trans
i18nKey={translationKey}
components={{
shortcut: <code className="p-1 rounded bg-vscode-button-background">{shortcut}</code>,
}}
/>
</p>
)
}
20 changes: 20 additions & 0 deletions webview-ui/src/hooks/usePlatform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useState, useEffect } from "react"

type Platform = "mac" | "windows" | "linux" | "unknown"

export function usePlatform(): Platform {
const [platform, setPlatform] = useState<Platform>("unknown")

useEffect(() => {
const userAgent = window.navigator.userAgent.toLowerCase()
if (userAgent.includes("mac")) {
setPlatform("mac")
} else if (userAgent.includes("win")) {
setPlatform("windows")
} else if (userAgent.includes("linux")) {
setPlatform("linux")
}
}, [])
Comment on lines +5 to +17
Copy link
Author

Choose a reason for hiding this comment

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

The hook initializes platform state as "unknown" and updates it in useEffect, causing the component to render twice (first with "unknown", then with the actual platform). While this works in VSCode webviews, consider using useMemo with direct platform detection to avoid the initial render with incorrect state, especially if this hook is reused in SSR contexts later.


return platform
}
3 changes: 2 additions & 1 deletion webview-ui/src/i18n/locales/en/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@
"triggerLabel_zero": "0 auto-approve",
"triggerLabel_one": "1 auto-approved",
"triggerLabel_other": "{{count}} auto-approved",
"triggerLabelAll": "YOLO"
"triggerLabelAll": "YOLO",
"toggleShortcut": "Toggle with <shortcut>"
},
"announcement": {
"title": "🎉 Roo Code {{version}} Released",
Expand Down
Loading