MCPcopy Create free account
hub / github.com/anomalyco/opencode / displayKeybindParts

Function displayKeybindParts

packages/app/src/context/command.tsx:173–216  ·  view source on GitHub ↗
(kb: Keybind, t?: (key: KeyLabel) => string)

Source from the content-addressed store, hash-verified

171}
172
173function displayKeybindParts(kb: Keybind, t?: (key: KeyLabel) => string) {
174 const parts: string[] = []
175
176 if (kb.ctrl) parts.push(IS_MAC ? "⌃" : keyText("common.key.ctrl", t))
177 if (kb.alt) parts.push(IS_MAC ? "⌥" : keyText("common.key.alt", t))
178 if (kb.shift) parts.push(IS_MAC ? "⇧" : keyText("common.key.shift", t))
179 if (kb.meta) parts.push(IS_MAC ? "⌘" : keyText("common.key.meta", t))
180
181 if (!kb.key) return parts
182
183 const keys: Record<string, string> = {
184 arrowup: "↑",
185 arrowdown: "↓",
186 arrowleft: "←",
187 arrowright: "→",
188 comma: ",",
189 plus: "+",
190 }
191 const named: Record<string, KeyLabel> = {
192 backspace: "common.key.backspace",
193 delete: "common.key.delete",
194 end: "common.key.end",
195 enter: "common.key.enter",
196 esc: "common.key.esc",
197 escape: "common.key.esc",
198 home: "common.key.home",
199 insert: "common.key.insert",
200 pagedown: "common.key.pageDown",
201 pageup: "common.key.pageUp",
202 space: "common.key.space",
203 tab: "common.key.tab",
204 }
205 const key = kb.key.toLowerCase()
206 const displayKey =
207 keys[key] ??
208 (named[key]
209 ? keyText(named[key], t)
210 : key.length === 1
211 ? key.toUpperCase()
212 : key.charAt(0).toUpperCase() + key.slice(1))
213 parts.push(displayKey)
214
215 return parts
216}
217
218export function formatKeybindParts(config: string, t?: (key: KeyLabel) => string): string[] {
219 if (!config || config === "none") return []

Callers 1

formatKeybindPartsFunction · 0.85

Calls 2

keyTextFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected