| 1 | import { useMemo } from "react"; |
| 2 | import Shortcut from "../../../../components/gui/Shortcut"; |
| 3 | import { isJetBrains } from "../../../../util"; |
| 4 | |
| 5 | interface KeyboardShortcutProps { |
| 6 | shortcut: string; |
| 7 | description: string; |
| 8 | isEven: boolean; |
| 9 | } |
| 10 | |
| 11 | function KeyboardShortcut(props: KeyboardShortcutProps) { |
| 12 | return ( |
| 13 | <div |
| 14 | className={`flex flex-col items-start p-2 sm:flex-row sm:items-center ${props.isEven ? "" : "bg-table-oddRow"}`} |
| 15 | > |
| 16 | <div className="w-full flex-grow pb-1 pr-4 sm:w-auto sm:pb-0"> |
| 17 | <span className="block break-words text-xs">{props.description}:</span> |
| 18 | </div> |
| 19 | <div className="flex-shrink-0 whitespace-nowrap"> |
| 20 | <Shortcut>{props.shortcut}</Shortcut> |
| 21 | </div> |
| 22 | </div> |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | // Shortcut strings will be rendered correctly based on the platform by the Shortcut component |
| 27 | const vscodeShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [ |
| 28 | { |
| 29 | shortcut: "cmd '", |
| 30 | description: "Toggle Selected Model", |
| 31 | }, |
| 32 | { |
| 33 | shortcut: "cmd I", |
| 34 | description: "Edit highlighted code", |
| 35 | }, |
| 36 | { |
| 37 | shortcut: "cmd L", |
| 38 | description: |
| 39 | "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus", |
| 40 | }, |
| 41 | { |
| 42 | shortcut: "cmd backspace", |
| 43 | description: "Cancel response", |
| 44 | }, |
| 45 | { |
| 46 | shortcut: "cmd shift I", |
| 47 | description: "Toggle inline edit focus", |
| 48 | }, |
| 49 | { |
| 50 | shortcut: "cmd shift L", |
| 51 | description: |
| 52 | "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus", |
| 53 | }, |
| 54 | { |
| 55 | shortcut: "cmd shift R", |
| 56 | description: "Debug Terminal", |
| 57 | }, |
| 58 | { |
| 59 | shortcut: "cmd shift backspace", |
| 60 | description: "Reject Diff", |
| 61 | }, |
| 62 | { |
| 63 | shortcut: "cmd shift enter", |
| 64 | description: "Accept Diff", |
| 65 | }, |
| 66 | { |
| 67 | shortcut: "alt cmd N", |
| 68 | description: "Reject Top Change in Diff", |
| 69 | }, |
| 70 | { |
| 71 | shortcut: "alt cmd Y", |
| 72 | description: "Accept Top Change in Diff", |
| 73 | }, |
| 74 | { |
| 75 | shortcut: "cmd K cmd A", |
| 76 | description: "Toggle Autocomplete Enabled", |
| 77 | }, |
| 78 | { |
| 79 | shortcut: "cmd alt space", |
| 80 | description: "Force an Autocomplete Trigger", |
| 81 | }, |
| 82 | { |
| 83 | shortcut: "cmd K cmd M", |
| 84 | description: "Toggle Full Screen", |
| 85 | }, |
| 86 | ]; |
| 87 | |
| 88 | const jetbrainsShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [ |
| 89 | { |
| 90 | shortcut: "cmd '", |
| 91 | description: "Toggle Selected Model", |
| 92 | }, |
| 93 | { |
| 94 | shortcut: "cmd I", |
| 95 | description: "Edit highlighted code", |
| 96 | }, |
| 97 | { |
| 98 | shortcut: "cmd J", |
| 99 | description: |
| 100 | "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus", |
| 101 | }, |
| 102 | { |
| 103 | shortcut: "cmd backspace", |
| 104 | description: "Cancel response", |
| 105 | }, |
| 106 | { |
| 107 | shortcut: "cmd shift I", |
| 108 | description: "Toggle inline edit focus", |
| 109 | }, |
| 110 | { |
| 111 | shortcut: "cmd shift J", |
| 112 | description: |
| 113 | "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus", |
| 114 | }, |
| 115 | { |
| 116 | shortcut: "cmd shift backspace", |
| 117 | description: "Reject Diff", |
| 118 | }, |
| 119 | { |
| 120 | shortcut: "cmd shift enter", |
| 121 | description: "Accept Diff", |
| 122 | }, |
| 123 | { |
| 124 | shortcut: "alt shift J", |
| 125 | description: "Quick Input", |
| 126 | }, |
| 127 | { |
| 128 | shortcut: "alt cmd J", |
| 129 | description: "Toggle Sidebar", |
| 130 | }, |
| 131 | ]; |
| 132 | |
| 133 | function KeyboardShortcuts() { |
| 134 | const shortcuts = useMemo(() => { |
| 135 | return isJetBrains() ? jetbrainsShortcuts : vscodeShortcuts; |
| 136 | }, []); |
| 137 | |
| 138 | return ( |
| 139 | <div className="h-full overflow-auto"> |
| 140 | <h3 className="mb-3 text-xl">Keyboard shortcuts</h3> |
| 141 | <div> |
| 142 | {shortcuts.map((shortcut, i) => { |
| 143 | return ( |
| 144 | <KeyboardShortcut |
| 145 | key={i} |
| 146 | shortcut={shortcut.shortcut} |
| 147 | description={shortcut.description} |
| 148 | isEven={i % 2 === 0} |
| 149 | /> |
| 150 | ); |
| 151 | })} |
| 152 | </div> |
| 153 | </div> |
| 154 | ); |
| 155 | } |
| 156 | |
| 157 | export default KeyboardShortcuts; |