fix(shortcuts): redesign keyboard shortcut settings with per-binding rows (#5850)
This commit is contained in:
@@ -23,7 +23,8 @@ const HOVER_REVEAL_FILES = [
|
||||
resolve(__dirname, 'right-sidebar/SourceControl.tsx'),
|
||||
resolve(__dirname, 'right-sidebar/checks-panel-content.tsx'),
|
||||
resolve(__dirname, 'settings/MobilePairingQrSection.tsx'),
|
||||
resolve(__dirname, 'settings/ShortcutBindingRow.tsx'),
|
||||
resolve(__dirname, 'settings/ShortcutBindingSubRow.tsx'),
|
||||
resolve(__dirname, 'settings/ShortcutCommandBlock.tsx'),
|
||||
resolve(__dirname, 'settings/VoiceSpeechModelSection.tsx'),
|
||||
resolve(__dirname, 'sidebar/HostSectionHeaderMenu.tsx'),
|
||||
resolve(__dirname, 'sidebar/PendingWorktreeRow.tsx'),
|
||||
|
||||
@@ -1,373 +0,0 @@
|
||||
import React, { useEffect, useRef } from 'react'
|
||||
import { Ban, Plus, RotateCcw, Terminal } from 'lucide-react'
|
||||
import {
|
||||
formatKeybinding,
|
||||
isDigitIndexActionId,
|
||||
isDoubleTapBinding,
|
||||
type KeybindingActionId,
|
||||
type KeybindingDefinition,
|
||||
type KeybindingInput
|
||||
} from '../../../../shared/keybindings'
|
||||
import {
|
||||
ModifierDoubleTapDetector,
|
||||
modifierFromKeyEvent,
|
||||
toModifierDoubleTapEvent
|
||||
} from '../../../../shared/modifier-double-tap-detector'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { ShortcutKeyCombo } from '../ShortcutKeyCombo'
|
||||
import { Badge } from '../ui/badge'
|
||||
import { Button } from '../ui/button'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'
|
||||
import { SearchableSetting } from './SearchableSetting'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
type ShortcutBindingRowProps = {
|
||||
item: KeybindingDefinition
|
||||
groupTitle: string
|
||||
platform: NodeJS.Platform
|
||||
effective: readonly string[]
|
||||
modified: boolean
|
||||
error?: string
|
||||
warnings: readonly string[]
|
||||
recording: boolean
|
||||
terminalStatus?: ShortcutTerminalStatus
|
||||
onStartRecording: (actionId: KeybindingActionId) => void
|
||||
onCancelRecording: () => void
|
||||
onCapture: (actionId: KeybindingActionId, input: KeybindingInput) => void
|
||||
onClearError: (actionId: KeybindingActionId) => void
|
||||
onDisable: (actionId: KeybindingActionId) => void
|
||||
onReset: (actionId: KeybindingActionId) => void
|
||||
}
|
||||
|
||||
export type ShortcutTerminalStatus = {
|
||||
label: string
|
||||
description: string
|
||||
}
|
||||
|
||||
// Why: digit-index rows store one representative chord (e.g. ⌘1) but fire for
|
||||
// 1-9, so the trailing number cap renders the whole range.
|
||||
function toDigitRangeKeys(keys: string[]): string[] {
|
||||
const last = keys.at(-1)
|
||||
if (last === undefined || !/^[1-9]$/.test(last)) {
|
||||
return keys
|
||||
}
|
||||
return [...keys.slice(0, -1), `${last}–9`]
|
||||
}
|
||||
|
||||
export function ShortcutBindingRow({
|
||||
item,
|
||||
groupTitle,
|
||||
platform,
|
||||
effective,
|
||||
modified,
|
||||
error,
|
||||
warnings,
|
||||
recording,
|
||||
terminalStatus,
|
||||
onStartRecording,
|
||||
onCancelRecording,
|
||||
onCapture,
|
||||
onClearError,
|
||||
onDisable,
|
||||
onReset
|
||||
}: ShortcutBindingRowProps): React.JSX.Element {
|
||||
const recordButtonRef = useRef<HTMLButtonElement | null>(null)
|
||||
const doubleTapDetectorRef = useRef<ModifierDoubleTapDetector | null>(null)
|
||||
if (!doubleTapDetectorRef.current) {
|
||||
doubleTapDetectorRef.current = new ModifierDoubleTapDetector()
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (recording) {
|
||||
recordButtonRef.current?.focus()
|
||||
} else {
|
||||
// Stale taps mustn't survive into the next recording session.
|
||||
doubleTapDetectorRef.current?.reset()
|
||||
}
|
||||
window.api.ui.setShortcutRecorderFocused(recording)
|
||||
return () => window.api.ui.setShortcutRecorderFocused(false)
|
||||
}, [recording])
|
||||
|
||||
const statusMessage = error ?? (warnings.length > 0 ? warnings.join(' ') : '')
|
||||
const doubleTapHint = platform === 'darwin' ? '⇧⇧' : 'Shift Shift'
|
||||
const recordingMessage = recording
|
||||
? translate(
|
||||
'auto.components.settings.ShortcutBindingRow.a98d551407',
|
||||
'Press a shortcut, or double-tap a modifier (e.g. {{value0}}). Esc cancels.',
|
||||
{ value0: doubleTapHint }
|
||||
)
|
||||
: ''
|
||||
const helperMessage = statusMessage || recordingMessage
|
||||
const hasBinding = effective.length > 0
|
||||
|
||||
const handleRecordKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>): void => {
|
||||
if (!recording) {
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault()
|
||||
onStartRecording(item.id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
if (event.key === 'Escape') {
|
||||
doubleTapDetectorRef.current?.reset()
|
||||
onClearError(item.id)
|
||||
onCancelRecording()
|
||||
return
|
||||
}
|
||||
|
||||
// A modifier press never captures on its own — the detector decides whether
|
||||
// it completes a double-tap, leaving normal chords to capture on their key.
|
||||
if (modifierFromKeyEvent(event.code, event.key) !== null) {
|
||||
const detected = doubleTapDetectorRef.current?.process(
|
||||
toModifierDoubleTapEvent({
|
||||
type: 'keyDown',
|
||||
code: event.code,
|
||||
key: event.key,
|
||||
shift: event.shiftKey,
|
||||
control: event.ctrlKey,
|
||||
alt: event.altKey,
|
||||
meta: event.metaKey,
|
||||
isAutoRepeat: event.repeat
|
||||
}),
|
||||
Date.now()
|
||||
)
|
||||
if (detected) {
|
||||
onClearError(item.id)
|
||||
onCapture(item.id, { doubleTapModifier: detected.modifier })
|
||||
doubleTapDetectorRef.current?.reset()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
doubleTapDetectorRef.current?.reset()
|
||||
onClearError(item.id)
|
||||
onCapture(item.id, {
|
||||
key: event.key,
|
||||
code: event.code,
|
||||
alt: event.altKey,
|
||||
meta: event.metaKey,
|
||||
control: event.ctrlKey,
|
||||
shift: event.shiftKey
|
||||
})
|
||||
}
|
||||
|
||||
const handleRecordKeyUp = (event: React.KeyboardEvent<HTMLButtonElement>): void => {
|
||||
if (!recording) {
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
doubleTapDetectorRef.current?.process(
|
||||
toModifierDoubleTapEvent({
|
||||
type: 'keyUp',
|
||||
code: event.code,
|
||||
key: event.key,
|
||||
shift: event.shiftKey,
|
||||
control: event.ctrlKey,
|
||||
alt: event.altKey,
|
||||
meta: event.metaKey
|
||||
}),
|
||||
Date.now()
|
||||
)
|
||||
}
|
||||
|
||||
// Why: the recorder is the row's primary control — clicking the keys (or the
|
||||
// "Add shortcut" placeholder) records a new binding in place, so the whole
|
||||
// affordance lives inline rather than in a detached popover.
|
||||
const recorderLabel = recording
|
||||
? `Press shortcut keys for ${item.title}. Escape cancels.`
|
||||
: hasBinding
|
||||
? `Change shortcut for ${item.title}`
|
||||
: `Add shortcut for ${item.title}`
|
||||
|
||||
const isDigitIndex = isDigitIndexActionId(item.id)
|
||||
|
||||
return (
|
||||
<SearchableSetting
|
||||
title={item.title}
|
||||
description={translate(
|
||||
'auto.components.settings.ShortcutBindingRow.3b11ef3a43',
|
||||
'{{value0}} shortcut',
|
||||
{ value0: groupTitle }
|
||||
)}
|
||||
keywords={[...item.searchKeywords]}
|
||||
className="group/shortcut relative flex min-h-[44px] max-w-none items-center gap-3 rounded-md px-2 py-1.5 transition-colors hover:bg-accent/40 focus-within:bg-accent/40"
|
||||
>
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<span className="truncate text-sm text-foreground">{item.title}</span>
|
||||
{modified ? (
|
||||
<Badge variant="outline" className="shrink-0 text-[11px]">
|
||||
{translate('auto.components.settings.ShortcutBindingRow.97dccee14e', 'Modified')}
|
||||
</Badge>
|
||||
) : null}
|
||||
{terminalStatus ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="shrink-0 gap-1 border-border/70 text-[11px] text-muted-foreground"
|
||||
>
|
||||
<Terminal className="size-3" />
|
||||
{terminalStatus.label}
|
||||
</Badge>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{terminalStatus.description}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
</div>
|
||||
{helperMessage ? (
|
||||
<span
|
||||
className={cn(
|
||||
'block truncate text-[11px] leading-4',
|
||||
error ? 'text-destructive' : 'text-muted-foreground'
|
||||
)}
|
||||
aria-live="polite"
|
||||
>
|
||||
{helperMessage}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
{/* Reset/Disable reveal on hover or keyboard focus to keep the row calm;
|
||||
they stay reachable via focus-within for keyboard users. */}
|
||||
{hasBinding ? (
|
||||
<div className="flex items-center gap-0.5 can-hover:opacity-0 transition-opacity group-hover/shortcut:opacity-100 group-focus-within/shortcut:opacity-100">
|
||||
{modified ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
aria-label={translate(
|
||||
'auto.components.settings.ShortcutBindingRow.4f2c9b2a05',
|
||||
'Reset {{value0}} to default',
|
||||
{ value0: item.title }
|
||||
)}
|
||||
onClick={() => onReset(item.id)}
|
||||
>
|
||||
<RotateCcw className="size-3" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutBindingRow.f75335b155',
|
||||
'Reset to default'
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
aria-label={translate(
|
||||
'auto.components.settings.ShortcutBindingRow.3b62c142fa',
|
||||
'Disable {{value0}}',
|
||||
{ value0: item.title }
|
||||
)}
|
||||
onClick={() => onDisable(item.id)}
|
||||
>
|
||||
<Ban className="size-3" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutBindingRow.9cdaaa3d8f',
|
||||
'Disable shortcut'
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
ref={recordButtonRef}
|
||||
type="button"
|
||||
aria-label={recorderLabel}
|
||||
aria-invalid={Boolean(error)}
|
||||
aria-pressed={recording}
|
||||
data-shortcut-recorder=""
|
||||
data-shortcut-recorder-active={recording ? '' : undefined}
|
||||
onClick={() => {
|
||||
if (!recording) {
|
||||
onStartRecording(item.id)
|
||||
}
|
||||
}}
|
||||
onKeyDown={handleRecordKeyDown}
|
||||
onKeyUp={handleRecordKeyUp}
|
||||
className={cn(
|
||||
'flex min-h-7 min-w-[5.5rem] items-center justify-center gap-1.5 rounded-md border px-2 py-1 text-xs outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring/50',
|
||||
recording
|
||||
? 'border-ring bg-accent text-accent-foreground ring-[3px] ring-ring/30'
|
||||
: hasBinding
|
||||
? 'border-transparent hover:border-border/70 hover:bg-background'
|
||||
: 'border-dashed border-border/70 text-muted-foreground hover:border-border hover:text-foreground'
|
||||
)}
|
||||
>
|
||||
{recording ? (
|
||||
<span className="px-1 text-muted-foreground">
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutBindingRow.87381fd8f8',
|
||||
'Press keys…'
|
||||
)}
|
||||
</span>
|
||||
) : hasBinding ? (
|
||||
<span className="flex flex-wrap items-center justify-end gap-1.5">
|
||||
{effective.map((binding) => {
|
||||
const keys = formatKeybinding(binding, platform)
|
||||
return (
|
||||
<ShortcutKeyCombo
|
||||
key={binding}
|
||||
keys={isDigitIndex ? toDigitRangeKeys(keys) : keys}
|
||||
doubleTap={isDoubleTapBinding(binding)}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</span>
|
||||
) : (
|
||||
<span className="flex items-center gap-1">
|
||||
<Plus className="size-3" />
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutBindingRow.4a4c2c9d32',
|
||||
'Add shortcut'
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{recording
|
||||
? translate(
|
||||
'auto.components.settings.ShortcutBindingRow.6a7848fdac',
|
||||
'Listening for shortcut'
|
||||
)
|
||||
: hasBinding
|
||||
? translate(
|
||||
'auto.components.settings.ShortcutBindingRow.f6579be67b',
|
||||
'Change shortcut'
|
||||
)
|
||||
: translate(
|
||||
'auto.components.settings.ShortcutBindingRow.4a4c2c9d32',
|
||||
'Add shortcut'
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</SearchableSetting>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import React from 'react'
|
||||
import type { KeybindingActionId, KeybindingInput } from '../../../../shared/keybindings'
|
||||
import { ShortcutRecorderButton } from './ShortcutRecorderButton'
|
||||
import { ShortcutRemoveButton } from './ShortcutRemoveButton'
|
||||
|
||||
type ShortcutBindingSubRowProps = {
|
||||
actionId: KeybindingActionId
|
||||
title: string
|
||||
platform: NodeJS.Platform
|
||||
isDigitIndex: boolean
|
||||
// The chord this row edits, or null for the transient "add a new binding" slot.
|
||||
binding: string | null
|
||||
bindingIndex: number
|
||||
bindingCount: number
|
||||
recording: boolean
|
||||
isAppendSlot?: boolean
|
||||
onStartRecording: (actionId: KeybindingActionId, index: number) => void
|
||||
onCancelRecording: () => void
|
||||
onCapture: (actionId: KeybindingActionId, input: KeybindingInput) => void
|
||||
onClearError: (actionId: KeybindingActionId) => void
|
||||
onRemove: (actionId: KeybindingActionId, index: number) => void
|
||||
}
|
||||
|
||||
// A second-or-later binding of an action. The chord sits at the right edge (so
|
||||
// chips line up with the binding on the command row); the remove control reveals
|
||||
// on hover.
|
||||
export function ShortcutBindingSubRow({
|
||||
actionId,
|
||||
title,
|
||||
platform,
|
||||
isDigitIndex,
|
||||
binding,
|
||||
bindingIndex,
|
||||
bindingCount,
|
||||
recording,
|
||||
isAppendSlot = false,
|
||||
onStartRecording,
|
||||
onCancelRecording,
|
||||
onCapture,
|
||||
onClearError,
|
||||
onRemove
|
||||
}: ShortcutBindingSubRowProps): React.JSX.Element {
|
||||
return (
|
||||
<div className="group/binding flex min-h-8 items-center gap-1 rounded-md py-0.5 pr-2 pl-5 transition-colors hover:bg-accent/30">
|
||||
<div className="min-w-0 flex-1" />
|
||||
{/* Remove reveals on hover/focus to keep the row calm; keyboard users
|
||||
reach it via focus-within. The append slot reserves the column with an
|
||||
invisible spacer so the recorder stays aligned across rows. */}
|
||||
{isAppendSlot ? (
|
||||
<span className="size-6 shrink-0" aria-hidden="true" />
|
||||
) : (
|
||||
<div className="can-hover:opacity-0 shrink-0 transition-opacity group-hover/binding:opacity-100 group-focus-within/binding:opacity-100">
|
||||
<ShortcutRemoveButton
|
||||
actionId={actionId}
|
||||
title={title}
|
||||
bindingIndex={bindingIndex}
|
||||
onRemove={onRemove}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="shrink-0">
|
||||
<ShortcutRecorderButton
|
||||
actionId={actionId}
|
||||
title={title}
|
||||
platform={platform}
|
||||
isDigitIndex={isDigitIndex}
|
||||
binding={binding}
|
||||
bindingIndex={bindingIndex}
|
||||
bindingCount={bindingCount}
|
||||
recording={recording}
|
||||
isAppendSlot={isAppendSlot}
|
||||
onStartRecording={onStartRecording}
|
||||
onCancelRecording={onCancelRecording}
|
||||
onCapture={onCapture}
|
||||
onClearError={onClearError}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
import React from 'react'
|
||||
import { Ban, Plus, RotateCcw, Terminal } from 'lucide-react'
|
||||
import {
|
||||
isDigitIndexActionId,
|
||||
type KeybindingActionId,
|
||||
type KeybindingDefinition,
|
||||
type KeybindingInput
|
||||
} from '../../../../shared/keybindings'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { Badge } from '../ui/badge'
|
||||
import { Button } from '../ui/button'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'
|
||||
import { SearchableSetting } from './SearchableSetting'
|
||||
import { ShortcutBindingSubRow } from './ShortcutBindingSubRow'
|
||||
import { ShortcutRecorderButton } from './ShortcutRecorderButton'
|
||||
import { ShortcutRemoveButton } from './ShortcutRemoveButton'
|
||||
import type { ShortcutTerminalStatus } from './shortcut-terminal-status'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
type ShortcutCommandBlockProps = {
|
||||
item: KeybindingDefinition
|
||||
groupTitle: string
|
||||
platform: NodeJS.Platform
|
||||
effective: readonly string[]
|
||||
modified: boolean
|
||||
error?: string
|
||||
warnings: readonly string[]
|
||||
terminalStatus?: ShortcutTerminalStatus
|
||||
// The bindings this action had right before it was disabled, so it can be
|
||||
// re-enabled with one click. Empty when there's nothing to restore.
|
||||
previousBindings: readonly string[]
|
||||
// Non-null only when this action is recording; the binding index being
|
||||
// recorded. Equal to effective.length when capturing a brand-new binding.
|
||||
recordingBindingIndex: number | null
|
||||
onStartRecordingAt: (actionId: KeybindingActionId, index: number) => void
|
||||
onAppendBinding: (actionId: KeybindingActionId) => void
|
||||
onCancelRecording: () => void
|
||||
onCapture: (actionId: KeybindingActionId, input: KeybindingInput) => void
|
||||
onClearError: (actionId: KeybindingActionId) => void
|
||||
onRemoveBindingAt: (actionId: KeybindingActionId, index: number) => void
|
||||
onResetAction: (actionId: KeybindingActionId) => void
|
||||
onDisableAction: (actionId: KeybindingActionId) => void
|
||||
onEnableAction: (actionId: KeybindingActionId) => void
|
||||
}
|
||||
|
||||
export function ShortcutCommandBlock({
|
||||
item,
|
||||
groupTitle,
|
||||
platform,
|
||||
effective,
|
||||
modified,
|
||||
error,
|
||||
warnings,
|
||||
terminalStatus,
|
||||
previousBindings,
|
||||
recordingBindingIndex,
|
||||
onStartRecordingAt,
|
||||
onAppendBinding,
|
||||
onCancelRecording,
|
||||
onCapture,
|
||||
onClearError,
|
||||
onRemoveBindingAt,
|
||||
onResetAction,
|
||||
onDisableAction,
|
||||
onEnableAction
|
||||
}: ShortcutCommandBlockProps): React.JSX.Element {
|
||||
const hasBinding = effective.length > 0
|
||||
const isMulti = effective.length >= 2
|
||||
// An explicit empty override means the user turned the action off entirely.
|
||||
const isDisabled = modified && !hasBinding
|
||||
const isRecording = recordingBindingIndex !== null
|
||||
const showAppendSlot = recordingBindingIndex !== null && recordingBindingIndex >= effective.length
|
||||
const isDigitIndex = isDigitIndexActionId(item.id)
|
||||
const canEnable = isDisabled && previousBindings.length > 0
|
||||
|
||||
const doubleTapHint = platform === 'darwin' ? '⇧⇧' : 'Shift Shift'
|
||||
const recordingMessage = translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.eb72c52c28',
|
||||
'Press a shortcut, or double-tap a modifier (e.g. {{value0}}). Esc cancels.',
|
||||
{ value0: doubleTapHint }
|
||||
)
|
||||
// Errors win, then the live recording hint, then a standing conflict warning.
|
||||
const helperMessage = error
|
||||
? error
|
||||
: isRecording
|
||||
? recordingMessage
|
||||
: warnings.length > 0
|
||||
? warnings.join(' ')
|
||||
: ''
|
||||
const helperTone = error || (!isRecording && warnings.length > 0) ? 'error' : 'muted'
|
||||
|
||||
const recorderFor = (binding: string | null, index: number): React.JSX.Element => (
|
||||
<ShortcutRecorderButton
|
||||
actionId={item.id}
|
||||
title={item.title}
|
||||
platform={platform}
|
||||
isDigitIndex={isDigitIndex}
|
||||
binding={binding}
|
||||
bindingIndex={index}
|
||||
bindingCount={effective.length}
|
||||
recording={recordingBindingIndex === index}
|
||||
onStartRecording={onStartRecordingAt}
|
||||
onCancelRecording={onCancelRecording}
|
||||
onCapture={onCapture}
|
||||
onClearError={onClearError}
|
||||
/>
|
||||
)
|
||||
|
||||
return (
|
||||
<SearchableSetting
|
||||
title={item.title}
|
||||
description={translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.70b5d25583',
|
||||
'{{value0}} shortcut',
|
||||
{ value0: groupTitle }
|
||||
)}
|
||||
keywords={[...item.searchKeywords]}
|
||||
className="group/shortcut flex max-w-none flex-col"
|
||||
>
|
||||
<div className="flex min-h-9 items-center gap-3 rounded-md px-2 py-1 transition-colors hover:bg-accent/40 focus-within:bg-accent/40">
|
||||
<div className="flex min-w-0 flex-1 items-center gap-2">
|
||||
<span
|
||||
className={cn(
|
||||
'truncate text-sm',
|
||||
isDisabled ? 'text-muted-foreground' : 'text-foreground'
|
||||
)}
|
||||
>
|
||||
{item.title}
|
||||
</span>
|
||||
{modified ? (
|
||||
<Badge variant="outline" className="shrink-0 text-[11px]">
|
||||
{translate('auto.components.settings.ShortcutCommandBlock.287e07ddde', 'Modified')}
|
||||
</Badge>
|
||||
) : null}
|
||||
{isDisabled ? (
|
||||
<Badge variant="outline" className="shrink-0 text-[11px] text-muted-foreground">
|
||||
{translate('auto.components.settings.ShortcutCommandBlock.3c83cd7d1c', 'Disabled')}
|
||||
</Badge>
|
||||
) : null}
|
||||
{terminalStatus && hasBinding ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="shrink-0 gap-1 border-border/70 text-[11px] text-muted-foreground"
|
||||
>
|
||||
<Terminal className="size-3" />
|
||||
{terminalStatus.label}
|
||||
</Badge>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{terminalStatus.description}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
{/* Action controls reveal on hover/focus to keep the list calm. Reset
|
||||
is gated on `modified` (not on having a binding) so it's reachable
|
||||
even when the action is disabled. */}
|
||||
<div className="can-hover:opacity-0 flex items-center gap-0.5 transition-opacity group-hover/shortcut:opacity-100 group-focus-within/shortcut:opacity-100">
|
||||
{hasBinding && !showAppendSlot ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
aria-label={translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.a0e2ef0e61',
|
||||
'Add another shortcut for {{value0}}',
|
||||
{ value0: item.title }
|
||||
)}
|
||||
onClick={() => onAppendBinding(item.id)}
|
||||
>
|
||||
<Plus className="size-3" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.245c83af24',
|
||||
'Add another shortcut'
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
{modified ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
aria-label={translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.07939d084e',
|
||||
'Reset {{value0}} to default',
|
||||
{ value0: item.title }
|
||||
)}
|
||||
onClick={() => onResetAction(item.id)}
|
||||
>
|
||||
<RotateCcw className="size-3" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.9b02917027',
|
||||
'Reset to default'
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
{hasBinding ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
aria-label={translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.a799f90f82',
|
||||
'Disable {{value0}}',
|
||||
{ value0: item.title }
|
||||
)}
|
||||
onClick={() => onDisableAction(item.id)}
|
||||
>
|
||||
<Ban className="size-3" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.25e6e76618',
|
||||
'Disable shortcut'
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
{/* Remove just the first binding (only meaningful when others
|
||||
remain; a single binding is turned off with Disable instead). */}
|
||||
{isMulti ? (
|
||||
<ShortcutRemoveButton
|
||||
actionId={item.id}
|
||||
title={item.title}
|
||||
bindingIndex={0}
|
||||
onRemove={onRemoveBindingAt}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* No binding: the primary affordance stays visible (the row would
|
||||
otherwise read as empty). Enable restores the pre-disable chord;
|
||||
otherwise Add records a fresh one. */}
|
||||
{!hasBinding && !showAppendSlot ? (
|
||||
canEnable ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
aria-label={translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.482a60225d',
|
||||
'Enable {{value0}}',
|
||||
{ value0: item.title }
|
||||
)}
|
||||
onClick={() => onEnableAction(item.id)}
|
||||
>
|
||||
{translate('auto.components.settings.ShortcutCommandBlock.6287677c37', 'Enable')}
|
||||
</Button>
|
||||
) : (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
aria-label={translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.01481b964c',
|
||||
'Add shortcut for {{value0}}',
|
||||
{ value0: item.title }
|
||||
)}
|
||||
onClick={() => onAppendBinding(item.id)}
|
||||
>
|
||||
<Plus className="size-3" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutCommandBlock.035a822ef0',
|
||||
'Add shortcut'
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
) : null}
|
||||
|
||||
{/* The first binding lives inline on the command row; extras stack
|
||||
below. A single-binding action is therefore one line. */}
|
||||
{hasBinding ? recorderFor(effective[0], 0) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{helperMessage ? (
|
||||
<span
|
||||
className={cn(
|
||||
'block truncate px-2 text-[11px] leading-4',
|
||||
helperTone === 'error' ? 'text-destructive' : 'text-muted-foreground'
|
||||
)}
|
||||
aria-live="polite"
|
||||
>
|
||||
{helperMessage}
|
||||
</span>
|
||||
) : null}
|
||||
|
||||
{/* Bindings beyond the first stack as their own rows under the command. */}
|
||||
{isMulti
|
||||
? effective.slice(1).map((binding, offset) => {
|
||||
const index = offset + 1
|
||||
return (
|
||||
<ShortcutBindingSubRow
|
||||
// Key by slot index, not the chord: editing a binding in place
|
||||
// keeps the same recorder element so focus survives the capture.
|
||||
key={index}
|
||||
actionId={item.id}
|
||||
title={item.title}
|
||||
platform={platform}
|
||||
isDigitIndex={isDigitIndex}
|
||||
binding={binding}
|
||||
bindingIndex={index}
|
||||
bindingCount={effective.length}
|
||||
recording={recordingBindingIndex === index}
|
||||
onStartRecording={onStartRecordingAt}
|
||||
onCancelRecording={onCancelRecording}
|
||||
onCapture={onCapture}
|
||||
onClearError={onClearError}
|
||||
onRemove={onRemoveBindingAt}
|
||||
/>
|
||||
)
|
||||
})
|
||||
: null}
|
||||
|
||||
{showAppendSlot ? (
|
||||
<ShortcutBindingSubRow
|
||||
key="append-slot"
|
||||
actionId={item.id}
|
||||
title={item.title}
|
||||
platform={platform}
|
||||
isDigitIndex={isDigitIndex}
|
||||
binding={null}
|
||||
bindingIndex={effective.length}
|
||||
bindingCount={effective.length + 1}
|
||||
recording
|
||||
isAppendSlot
|
||||
onStartRecording={onStartRecordingAt}
|
||||
onCancelRecording={onCancelRecording}
|
||||
onCapture={onCapture}
|
||||
onClearError={onClearError}
|
||||
onRemove={onRemoveBindingAt}
|
||||
/>
|
||||
) : null}
|
||||
</SearchableSetting>
|
||||
)
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { formatKeybindingList, type KeybindingDefinition } from '../../../../sha
|
||||
import { cn } from '../../lib/utils'
|
||||
import { Button } from '../ui/button'
|
||||
import { Input } from '../ui/input'
|
||||
import type { ShortcutTerminalStatus } from './ShortcutBindingRow'
|
||||
import type { ShortcutTerminalStatus } from './shortcut-terminal-status'
|
||||
import type { SettingsSearchEntry } from './settings-search'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
import React, { useEffect, useRef } from 'react'
|
||||
import {
|
||||
formatKeybinding,
|
||||
isDoubleTapBinding,
|
||||
type KeybindingActionId,
|
||||
type KeybindingInput
|
||||
} from '../../../../shared/keybindings'
|
||||
import {
|
||||
ModifierDoubleTapDetector,
|
||||
modifierFromKeyEvent,
|
||||
toModifierDoubleTapEvent
|
||||
} from '../../../../shared/modifier-double-tap-detector'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { ShortcutKeyCombo } from '../ShortcutKeyCombo'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
type ShortcutRecorderButtonProps = {
|
||||
actionId: KeybindingActionId
|
||||
title: string
|
||||
platform: NodeJS.Platform
|
||||
isDigitIndex: boolean
|
||||
// The chord this button edits, or null for the transient "add a new binding" slot.
|
||||
binding: string | null
|
||||
bindingIndex: number
|
||||
bindingCount: number
|
||||
recording: boolean
|
||||
isAppendSlot?: boolean
|
||||
onStartRecording: (actionId: KeybindingActionId, index: number) => void
|
||||
onCancelRecording: () => void
|
||||
onCapture: (actionId: KeybindingActionId, input: KeybindingInput) => void
|
||||
onClearError: (actionId: KeybindingActionId) => void
|
||||
}
|
||||
|
||||
// Why: digit-index rows store one representative chord (e.g. ⌘1) but fire for
|
||||
// 1-9, so the trailing number cap renders the whole range.
|
||||
function toDigitRangeKeys(keys: string[]): string[] {
|
||||
const last = keys.at(-1)
|
||||
if (last === undefined || !/^[1-9]$/.test(last)) {
|
||||
return keys
|
||||
}
|
||||
return [...keys.slice(0, -1), `${last}–9`]
|
||||
}
|
||||
|
||||
export function ShortcutRecorderButton({
|
||||
actionId,
|
||||
title,
|
||||
platform,
|
||||
isDigitIndex,
|
||||
binding,
|
||||
bindingIndex,
|
||||
bindingCount,
|
||||
recording,
|
||||
isAppendSlot = false,
|
||||
onStartRecording,
|
||||
onCancelRecording,
|
||||
onCapture,
|
||||
onClearError
|
||||
}: ShortcutRecorderButtonProps): React.JSX.Element {
|
||||
const recordButtonRef = useRef<HTMLButtonElement | null>(null)
|
||||
const doubleTapDetectorRef = useRef<ModifierDoubleTapDetector | null>(null)
|
||||
if (!doubleTapDetectorRef.current) {
|
||||
doubleTapDetectorRef.current = new ModifierDoubleTapDetector()
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (recording) {
|
||||
recordButtonRef.current?.focus()
|
||||
} else {
|
||||
// Stale taps mustn't survive into the next recording session.
|
||||
doubleTapDetectorRef.current?.reset()
|
||||
}
|
||||
// The global recorder-focused flag is owned by ShortcutsPane (one source of
|
||||
// truth across rows), so it isn't toggled here.
|
||||
}, [recording])
|
||||
|
||||
const handleRecordKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>): void => {
|
||||
if (!recording) {
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault()
|
||||
onStartRecording(actionId, bindingIndex)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
if (event.key === 'Escape') {
|
||||
doubleTapDetectorRef.current?.reset()
|
||||
onClearError(actionId)
|
||||
onCancelRecording()
|
||||
return
|
||||
}
|
||||
|
||||
// A modifier press never captures on its own — the detector decides whether
|
||||
// it completes a double-tap, leaving normal chords to capture on their key.
|
||||
if (modifierFromKeyEvent(event.code, event.key) !== null) {
|
||||
const detected = doubleTapDetectorRef.current?.process(
|
||||
toModifierDoubleTapEvent({
|
||||
type: 'keyDown',
|
||||
code: event.code,
|
||||
key: event.key,
|
||||
shift: event.shiftKey,
|
||||
control: event.ctrlKey,
|
||||
alt: event.altKey,
|
||||
meta: event.metaKey,
|
||||
isAutoRepeat: event.repeat
|
||||
}),
|
||||
Date.now()
|
||||
)
|
||||
if (detected) {
|
||||
onClearError(actionId)
|
||||
onCapture(actionId, { doubleTapModifier: detected.modifier })
|
||||
doubleTapDetectorRef.current?.reset()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
doubleTapDetectorRef.current?.reset()
|
||||
onClearError(actionId)
|
||||
onCapture(actionId, {
|
||||
key: event.key,
|
||||
code: event.code,
|
||||
alt: event.altKey,
|
||||
meta: event.metaKey,
|
||||
control: event.ctrlKey,
|
||||
shift: event.shiftKey
|
||||
})
|
||||
}
|
||||
|
||||
const handleRecordKeyUp = (event: React.KeyboardEvent<HTMLButtonElement>): void => {
|
||||
if (!recording) {
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
doubleTapDetectorRef.current?.process(
|
||||
toModifierDoubleTapEvent({
|
||||
type: 'keyUp',
|
||||
code: event.code,
|
||||
key: event.key,
|
||||
shift: event.shiftKey,
|
||||
control: event.ctrlKey,
|
||||
alt: event.altKey,
|
||||
meta: event.metaKey
|
||||
}),
|
||||
Date.now()
|
||||
)
|
||||
}
|
||||
|
||||
const recorderLabel = recording
|
||||
? translate(
|
||||
'auto.components.settings.ShortcutRecorderButton.1a13bb054d',
|
||||
'Press shortcut keys for {{value0}}. Escape cancels.',
|
||||
{ value0: title }
|
||||
)
|
||||
: isAppendSlot || binding === null
|
||||
? translate(
|
||||
'auto.components.settings.ShortcutRecorderButton.3732775d74',
|
||||
'Add shortcut for {{value0}}',
|
||||
{ value0: title }
|
||||
)
|
||||
: bindingCount <= 1
|
||||
? translate(
|
||||
'auto.components.settings.ShortcutRecorderButton.88764af2c1',
|
||||
'Change shortcut for {{value0}}',
|
||||
{ value0: title }
|
||||
)
|
||||
: translate(
|
||||
'auto.components.settings.ShortcutRecorderButton.30feb099d6',
|
||||
'Change shortcut {{value0}} of {{value1}} for {{value2}}',
|
||||
{ value0: String(bindingIndex + 1), value1: String(bindingCount), value2: title }
|
||||
)
|
||||
|
||||
const tooltipLabel = recording
|
||||
? translate(
|
||||
'auto.components.settings.ShortcutRecorderButton.5d982a2a1f',
|
||||
'Listening for shortcut'
|
||||
)
|
||||
: isAppendSlot || binding === null
|
||||
? translate('auto.components.settings.ShortcutRecorderButton.152e0bcd64', 'Add shortcut')
|
||||
: translate('auto.components.settings.ShortcutRecorderButton.5bd56445da', 'Change shortcut')
|
||||
|
||||
const keys = binding === null ? [] : formatKeybinding(binding, platform)
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
ref={recordButtonRef}
|
||||
type="button"
|
||||
aria-label={recorderLabel}
|
||||
aria-pressed={recording}
|
||||
data-shortcut-recorder=""
|
||||
data-shortcut-recorder-active={recording ? '' : undefined}
|
||||
onClick={() => {
|
||||
if (!recording) {
|
||||
onStartRecording(actionId, bindingIndex)
|
||||
}
|
||||
}}
|
||||
onKeyDown={handleRecordKeyDown}
|
||||
onKeyUp={handleRecordKeyUp}
|
||||
className={cn(
|
||||
'flex min-h-7 min-w-[5.5rem] max-w-[14rem] items-center justify-end gap-1.5 overflow-hidden rounded-md border px-2 py-1 text-xs outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring/50',
|
||||
recording
|
||||
? 'border-ring bg-accent text-accent-foreground ring-[3px] ring-ring/30'
|
||||
: 'border-transparent hover:border-border/70 hover:bg-background'
|
||||
)}
|
||||
>
|
||||
{recording || binding === null ? (
|
||||
<span className="px-1 text-muted-foreground">
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutRecorderButton.f5ed5dcbf6',
|
||||
'Press keys…'
|
||||
)}
|
||||
</span>
|
||||
) : (
|
||||
<span className="flex flex-wrap items-center justify-end gap-1.5 overflow-hidden">
|
||||
<ShortcutKeyCombo
|
||||
keys={isDigitIndex ? toDigitRangeKeys(keys) : keys}
|
||||
doubleTap={isDoubleTapBinding(binding)}
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{tooltipLabel}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import React from 'react'
|
||||
import { X } from 'lucide-react'
|
||||
import type { KeybindingActionId } from '../../../../shared/keybindings'
|
||||
import { Button } from '../ui/button'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
// Removes one binding from an action. The hover-reveal wrapper lives in the
|
||||
// parent row so it can key off that row's hover group (the header row and the
|
||||
// sub-rows use different group names).
|
||||
export function ShortcutRemoveButton({
|
||||
actionId,
|
||||
title,
|
||||
bindingIndex,
|
||||
onRemove
|
||||
}: {
|
||||
actionId: KeybindingActionId
|
||||
title: string
|
||||
bindingIndex: number
|
||||
onRemove: (actionId: KeybindingActionId, index: number) => void
|
||||
}): React.JSX.Element {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
aria-label={translate(
|
||||
'auto.components.settings.ShortcutRemoveButton.9e29aff18b',
|
||||
'Remove {{value0}} shortcut {{value1}}',
|
||||
{ value0: title, value1: String(bindingIndex + 1) }
|
||||
)}
|
||||
onClick={() => onRemove(actionId, bindingIndex)}
|
||||
>
|
||||
<X className="size-3" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={4}>
|
||||
{translate(
|
||||
'auto.components.settings.ShortcutRemoveButton.2a9588b1c2',
|
||||
'Remove this binding'
|
||||
)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
@@ -1,34 +1,46 @@
|
||||
import React from 'react'
|
||||
import type { KeybindingActionId, KeybindingInput } from '../../../../shared/keybindings'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { ShortcutBindingRow } from './ShortcutBindingRow'
|
||||
import { ShortcutCommandBlock } from './ShortcutCommandBlock'
|
||||
import type { ShortcutRowsByGroup } from './ShortcutFilterRail'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
const EMPTY_BINDINGS: readonly string[] = []
|
||||
|
||||
export function ShortcutRowsList({
|
||||
className,
|
||||
groups,
|
||||
platform,
|
||||
errors,
|
||||
disableMemory,
|
||||
recordingActionId,
|
||||
onStartRecording,
|
||||
recordingBindingIndex,
|
||||
onStartRecordingAt,
|
||||
onAppendBinding,
|
||||
onCancelRecording,
|
||||
onCapture,
|
||||
onClearError,
|
||||
onDisable,
|
||||
onReset
|
||||
onRemoveBindingAt,
|
||||
onResetAction,
|
||||
onDisableAction,
|
||||
onEnableAction
|
||||
}: {
|
||||
className?: string
|
||||
groups: ShortcutRowsByGroup[]
|
||||
platform: NodeJS.Platform
|
||||
errors: Partial<Record<KeybindingActionId, string>>
|
||||
disableMemory: Partial<Record<KeybindingActionId, string[]>>
|
||||
recordingActionId: KeybindingActionId | null
|
||||
onStartRecording: (actionId: KeybindingActionId) => void
|
||||
recordingBindingIndex: number | null
|
||||
onStartRecordingAt: (actionId: KeybindingActionId, index: number) => void
|
||||
onAppendBinding: (actionId: KeybindingActionId) => void
|
||||
onCancelRecording: () => void
|
||||
onCapture: (actionId: KeybindingActionId, input: KeybindingInput) => void
|
||||
onClearError: (actionId: KeybindingActionId) => void
|
||||
onDisable: (actionId: KeybindingActionId) => void
|
||||
onReset: (actionId: KeybindingActionId) => void
|
||||
onRemoveBindingAt: (actionId: KeybindingActionId, index: number) => void
|
||||
onResetAction: (actionId: KeybindingActionId) => void
|
||||
onDisableAction: (actionId: KeybindingActionId) => void
|
||||
onEnableAction: (actionId: KeybindingActionId) => void
|
||||
}): React.JSX.Element {
|
||||
if (groups.length === 0) {
|
||||
return (
|
||||
@@ -53,9 +65,9 @@ export function ShortcutRowsList({
|
||||
<h3 className="border-b border-border/50 pb-2 text-sm font-medium text-muted-foreground">
|
||||
{group.title}
|
||||
</h3>
|
||||
<div className="grid gap-2">
|
||||
<div className="flex flex-col gap-3">
|
||||
{group.rows.map((row) => (
|
||||
<ShortcutBindingRow
|
||||
<ShortcutCommandBlock
|
||||
key={row.item.id}
|
||||
item={row.item}
|
||||
groupTitle={group.title}
|
||||
@@ -64,14 +76,20 @@ export function ShortcutRowsList({
|
||||
modified={row.modified}
|
||||
error={errors[row.item.id]}
|
||||
warnings={row.warnings}
|
||||
recording={recordingActionId === row.item.id}
|
||||
terminalStatus={row.terminalStatus}
|
||||
onStartRecording={onStartRecording}
|
||||
previousBindings={disableMemory[row.item.id] ?? EMPTY_BINDINGS}
|
||||
recordingBindingIndex={
|
||||
recordingActionId === row.item.id ? recordingBindingIndex : null
|
||||
}
|
||||
onStartRecordingAt={onStartRecordingAt}
|
||||
onAppendBinding={onAppendBinding}
|
||||
onCancelRecording={onCancelRecording}
|
||||
onCapture={onCapture}
|
||||
onClearError={onClearError}
|
||||
onDisable={onDisable}
|
||||
onReset={onReset}
|
||||
onRemoveBindingAt={onRemoveBindingAt}
|
||||
onResetAction={onResetAction}
|
||||
onDisableAction={onDisableAction}
|
||||
onEnableAction={onEnableAction}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
import React, { useMemo, useState } from 'react'
|
||||
import React, { useEffect, useMemo, useState } from 'react'
|
||||
import {
|
||||
findKeybindingConflicts,
|
||||
formatKeybindingList,
|
||||
getEffectiveKeybindingsForAction,
|
||||
getKeybindingDefinition,
|
||||
isKeybindingAllowedInTerminal,
|
||||
isKeybindingPotentialTerminalConflict,
|
||||
keybindingFromInputForAction,
|
||||
keybindingIsActiveInContext,
|
||||
normalizeKeybindingListForAction,
|
||||
type KeybindingActionId,
|
||||
type KeybindingDefinition,
|
||||
type KeybindingInput,
|
||||
type KeybindingOverrides,
|
||||
type TerminalShortcutPolicy
|
||||
type KeybindingInput
|
||||
} from '../../../../shared/keybindings'
|
||||
import {
|
||||
EMPTY_DISABLED_TUI_AGENTS,
|
||||
@@ -23,7 +17,13 @@ import {
|
||||
import { useAppStore } from '../../store'
|
||||
import { KeybindingsFileActions } from './KeybindingsFileActions'
|
||||
import { SettingsSubsectionHeader } from './SettingsFormControls'
|
||||
import type { ShortcutTerminalStatus } from './ShortcutBindingRow'
|
||||
import { getShortcutTerminalStatus } from './shortcut-terminal-status'
|
||||
import {
|
||||
hasCommonBindingOverride,
|
||||
hasOwnBindingOverride,
|
||||
removeBindingOverride,
|
||||
sameBindings
|
||||
} from './keybinding-override-edits'
|
||||
import {
|
||||
getShortcutSearchEntry,
|
||||
matchesShortcutFilter,
|
||||
@@ -37,6 +37,12 @@ import { ShortcutTerminalPolicyControl } from './ShortcutTerminalPolicyControl'
|
||||
import { getTerminalShortcutPolicySearchEntry } from './shortcuts-search'
|
||||
import { matchesSettingsSearch, normalizeSettingsSearchQuery } from './settings-search'
|
||||
import { clearRecordingActionForShortcutMutation } from './shortcut-recording-state'
|
||||
import {
|
||||
adjustRecordingIndexAfterRemove,
|
||||
appendBinding,
|
||||
removeBindingAt,
|
||||
replaceBindingAt
|
||||
} from './shortcut-binding-list-mutations'
|
||||
import { useMountedRef } from '@/hooks/useMountedRef'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
@@ -47,83 +53,6 @@ const platform: NodeJS.Platform = isMac
|
||||
? 'win32'
|
||||
: 'linux'
|
||||
|
||||
function sameBindings(a: readonly string[], b: readonly string[]): boolean {
|
||||
return a.length === b.length && a.every((binding, index) => binding === b[index])
|
||||
}
|
||||
|
||||
function hasOwnBindingOverride(
|
||||
overrides: KeybindingOverrides,
|
||||
actionId: KeybindingActionId
|
||||
): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(overrides, actionId)
|
||||
}
|
||||
|
||||
function removeBindingOverride(
|
||||
overrides: KeybindingOverrides,
|
||||
actionId: KeybindingActionId
|
||||
): KeybindingOverrides {
|
||||
const next = { ...overrides }
|
||||
delete next[actionId]
|
||||
return next
|
||||
}
|
||||
|
||||
function hasCommonBindingOverride(
|
||||
snapshot: ReturnType<typeof useAppStore.getState>['keybindingSnapshot'],
|
||||
actionId: KeybindingActionId
|
||||
): boolean {
|
||||
return hasOwnBindingOverride(snapshot?.commonOverrides ?? {}, actionId)
|
||||
}
|
||||
|
||||
function getShortcutTerminalStatus(
|
||||
definition: KeybindingDefinition,
|
||||
terminalShortcutPolicy: TerminalShortcutPolicy,
|
||||
hasEffectiveBinding: boolean
|
||||
): ShortcutTerminalStatus | undefined {
|
||||
if (!hasEffectiveBinding) {
|
||||
return undefined
|
||||
}
|
||||
if (definition.scope === 'terminal') {
|
||||
return {
|
||||
label: translate('auto.components.settings.ShortcutsPane.cb02e00202', 'Terminal'),
|
||||
description: translate(
|
||||
'auto.components.settings.ShortcutsPane.781cb74d22',
|
||||
'Runs from terminal panes.'
|
||||
)
|
||||
}
|
||||
}
|
||||
if (isKeybindingAllowedInTerminal(definition)) {
|
||||
return {
|
||||
label: translate('auto.components.settings.ShortcutsPane.25b0004fbf', 'Terminal active'),
|
||||
description: translate(
|
||||
'auto.components.settings.ShortcutsPane.3c0fac059a',
|
||||
'Still runs while a terminal has keyboard focus.'
|
||||
)
|
||||
}
|
||||
}
|
||||
if (!isKeybindingPotentialTerminalConflict(definition)) {
|
||||
return undefined
|
||||
}
|
||||
const activeInTerminal = keybindingIsActiveInContext(definition, {
|
||||
context: 'terminal',
|
||||
terminalShortcutPolicy
|
||||
})
|
||||
return activeInTerminal
|
||||
? {
|
||||
label: translate('auto.components.settings.ShortcutsPane.2a0e8aeccf', 'Orca first'),
|
||||
description: translate(
|
||||
'auto.components.settings.ShortcutsPane.dfa8ff612f',
|
||||
'Also runs while a terminal or TUI has keyboard focus.'
|
||||
)
|
||||
}
|
||||
: {
|
||||
label: translate('auto.components.settings.ShortcutsPane.5c65d5db9d', 'Terminal first'),
|
||||
description: translate(
|
||||
'auto.components.settings.ShortcutsPane.f0b35b0b2e',
|
||||
'Disabled while a terminal or TUI has keyboard focus.'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function ShortcutsPane(): React.JSX.Element {
|
||||
const searchQuery = useAppStore((state) => state.settingsSearchQuery)
|
||||
const terminalShortcutPolicy = useAppStore(
|
||||
@@ -141,9 +70,25 @@ export function ShortcutsPane(): React.JSX.Element {
|
||||
const mountedRef = useMountedRef()
|
||||
const [errors, setErrors] = useState<Partial<Record<KeybindingActionId, string>>>({})
|
||||
const [recordingActionId, setRecordingActionId] = useState<KeybindingActionId | null>(null)
|
||||
// Which binding index of the recording action is being captured. Equals the
|
||||
// effective length when capturing a brand-new (appended) binding.
|
||||
const [recordingBindingIndex, setRecordingBindingIndex] = useState<number | null>(null)
|
||||
// Bindings an action had right before it was disabled, so "Enable" can restore
|
||||
// them in one click instead of forcing a reset-to-default.
|
||||
const [disableMemory, setDisableMemory] = useState<Partial<Record<KeybindingActionId, string[]>>>(
|
||||
{}
|
||||
)
|
||||
const [shortcutQuery, setShortcutQuery] = useState('')
|
||||
const [shortcutFilter, setShortcutFilter] = useState<ShortcutFilter>('all')
|
||||
|
||||
// Why: tell the main process to suspend global shortcut dispatch while any row
|
||||
// is recording, so the captured chord lands in the editor instead of firing.
|
||||
// One source of truth here avoids races between per-row recorder effects.
|
||||
useEffect(() => {
|
||||
window.api.ui.setShortcutRecorderFocused(recordingActionId !== null)
|
||||
return () => window.api.ui.setShortcutRecorderFocused(false)
|
||||
}, [recordingActionId])
|
||||
|
||||
const groups = useMemo(() => groupDefinitions(disabledTuiAgents), [disabledTuiAgents])
|
||||
const ignoredConflictActionIds = useMemo(
|
||||
() => disabledAgentTabActionIds(disabledTuiAgents),
|
||||
@@ -283,13 +228,25 @@ export function ShortcutsPane(): React.JSX.Element {
|
||||
return
|
||||
}
|
||||
|
||||
// Why: the visual editor records one chord at a time; users can still
|
||||
// manage multi-binding arrays directly in keybindings.json.
|
||||
if ((await saveBindings(actionId, [captured.value])) && mountedRef.current) {
|
||||
// Edit just the targeted binding (or append a new one) instead of replacing
|
||||
// the whole list, so an action's other bindings survive the capture.
|
||||
const current = getEffectiveKeybindingsForAction(actionId, platform, keybindings)
|
||||
const next =
|
||||
recordingBindingIndex === null || recordingBindingIndex >= current.length
|
||||
? appendBinding(current, captured.value)
|
||||
: replaceBindingAt(current, recordingBindingIndex, captured.value)
|
||||
if ((await saveBindings(actionId, next)) && mountedRef.current) {
|
||||
setRecordingActionId(null)
|
||||
setRecordingBindingIndex(null)
|
||||
}
|
||||
}
|
||||
|
||||
const removeBinding = async (actionId: KeybindingActionId, index: number): Promise<void> => {
|
||||
setErrors((prev) => ({ ...prev, [actionId]: undefined }))
|
||||
const current = getEffectiveKeybindingsForAction(actionId, platform, keybindings)
|
||||
await saveBindings(actionId, removeBindingAt(current, index))
|
||||
}
|
||||
|
||||
const resetBinding = async (actionId: KeybindingActionId): Promise<void> => {
|
||||
setErrors((prev) => ({ ...prev, [actionId]: undefined }))
|
||||
try {
|
||||
@@ -327,6 +284,9 @@ export function ShortcutsPane(): React.JSX.Element {
|
||||
const clearRecordingForAction = (actionId: KeybindingActionId): void => {
|
||||
// Why: disable/reset are final shortcut edits; the next keypress must not
|
||||
// be captured into the shortcut the user just removed or restored.
|
||||
if (recordingActionId === actionId) {
|
||||
setRecordingBindingIndex(null)
|
||||
}
|
||||
setRecordingActionId((current) => clearRecordingActionForShortcutMutation(current, actionId))
|
||||
}
|
||||
|
||||
@@ -396,25 +356,61 @@ export function ShortcutsPane(): React.JSX.Element {
|
||||
/>
|
||||
|
||||
<ShortcutRowsList
|
||||
className="min-h-0 min-w-0 flex-1 overflow-y-auto pr-1 scrollbar-sleek"
|
||||
// overflow-x-hidden is explicit: overflow-y-auto alone makes the
|
||||
// browser compute overflow-x to auto, which produced the phantom
|
||||
// horizontal scroll when long edit-time content popped in.
|
||||
className="min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto pr-1 scrollbar-sleek"
|
||||
groups={visibleShortcutGroups}
|
||||
platform={platform}
|
||||
errors={errors}
|
||||
disableMemory={disableMemory}
|
||||
recordingActionId={recordingActionId}
|
||||
onStartRecording={(actionId) => {
|
||||
recordingBindingIndex={recordingBindingIndex}
|
||||
onStartRecordingAt={(actionId, index) => {
|
||||
setRecordingActionId(actionId)
|
||||
setRecordingBindingIndex(index)
|
||||
clearError(actionId)
|
||||
}}
|
||||
onCancelRecording={() => setRecordingActionId(null)}
|
||||
onAppendBinding={(actionId) => {
|
||||
const current = getEffectiveKeybindingsForAction(actionId, platform, keybindings)
|
||||
setRecordingActionId(actionId)
|
||||
setRecordingBindingIndex(current.length)
|
||||
clearError(actionId)
|
||||
}}
|
||||
onCancelRecording={() => {
|
||||
setRecordingActionId(null)
|
||||
setRecordingBindingIndex(null)
|
||||
}}
|
||||
onCapture={(actionId, input) => void captureBinding(actionId, input)}
|
||||
onClearError={clearError}
|
||||
onDisable={(actionId) => {
|
||||
onRemoveBindingAt={(actionId, index) => {
|
||||
// Keep a pending capture aimed at the right row after the removal
|
||||
// shifts indices (or clear it if the recorded row itself is gone).
|
||||
if (recordingActionId === actionId) {
|
||||
const nextIndex = adjustRecordingIndexAfterRemove(recordingBindingIndex, index)
|
||||
setRecordingBindingIndex(nextIndex)
|
||||
if (nextIndex === null) {
|
||||
setRecordingActionId(null)
|
||||
}
|
||||
}
|
||||
void removeBinding(actionId, index)
|
||||
}}
|
||||
onResetAction={(actionId) => {
|
||||
clearRecordingForAction(actionId)
|
||||
void resetBinding(actionId)
|
||||
}}
|
||||
onDisableAction={(actionId) => {
|
||||
// Remember the current bindings first so "Enable" can restore them.
|
||||
const current = getEffectiveKeybindingsForAction(actionId, platform, keybindings)
|
||||
setDisableMemory((memory) => ({ ...memory, [actionId]: current }))
|
||||
clearRecordingForAction(actionId)
|
||||
void disableBinding(actionId)
|
||||
}}
|
||||
onReset={(actionId) => {
|
||||
clearRecordingForAction(actionId)
|
||||
void resetBinding(actionId)
|
||||
onEnableAction={(actionId) => {
|
||||
const remembered = disableMemory[actionId]
|
||||
if (remembered && remembered.length > 0) {
|
||||
void saveBindings(actionId, remembered)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import type {
|
||||
KeybindingActionId,
|
||||
KeybindingFileSnapshot,
|
||||
KeybindingOverrides
|
||||
} from '../../../../shared/keybindings'
|
||||
|
||||
// Predicates and edits on the per-action overrides map (distinct from
|
||||
// shortcut-binding-list-mutations, which edits a single action's binding array).
|
||||
|
||||
export function sameBindings(a: readonly string[], b: readonly string[]): boolean {
|
||||
return a.length === b.length && a.every((binding, index) => binding === b[index])
|
||||
}
|
||||
|
||||
export function hasOwnBindingOverride(
|
||||
overrides: KeybindingOverrides,
|
||||
actionId: KeybindingActionId
|
||||
): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(overrides, actionId)
|
||||
}
|
||||
|
||||
export function removeBindingOverride(
|
||||
overrides: KeybindingOverrides,
|
||||
actionId: KeybindingActionId
|
||||
): KeybindingOverrides {
|
||||
const next = { ...overrides }
|
||||
delete next[actionId]
|
||||
return next
|
||||
}
|
||||
|
||||
// Why: a common (cross-platform) override must be replaced, not deleted, when
|
||||
// the user resets — deleting only the platform layer would fall back to it.
|
||||
export function hasCommonBindingOverride(
|
||||
snapshot: KeybindingFileSnapshot | null,
|
||||
actionId: KeybindingActionId
|
||||
): boolean {
|
||||
return hasOwnBindingOverride(snapshot?.commonOverrides ?? {}, actionId)
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
adjustRecordingIndexAfterRemove,
|
||||
appendBinding,
|
||||
removeBindingAt,
|
||||
replaceBindingAt
|
||||
} from './shortcut-binding-list-mutations'
|
||||
|
||||
describe('appendBinding', () => {
|
||||
it('appends to the end and returns a new array', () => {
|
||||
const list = ['Cmd+S']
|
||||
const next = appendBinding(list, 'Ctrl+S')
|
||||
expect(next).toEqual(['Cmd+S', 'Ctrl+S'])
|
||||
expect(next).not.toBe(list)
|
||||
expect(list).toEqual(['Cmd+S'])
|
||||
})
|
||||
|
||||
it('handles an empty list', () => {
|
||||
expect(appendBinding([], 'Cmd+S')).toEqual(['Cmd+S'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('replaceBindingAt', () => {
|
||||
it('replaces the element at the index without changing length', () => {
|
||||
expect(replaceBindingAt(['a', 'b', 'c'], 1, 'B')).toEqual(['a', 'B', 'c'])
|
||||
})
|
||||
|
||||
it('replaces the first and last elements', () => {
|
||||
expect(replaceBindingAt(['a', 'b', 'c'], 0, 'A')).toEqual(['A', 'b', 'c'])
|
||||
expect(replaceBindingAt(['a', 'b', 'c'], 2, 'C')).toEqual(['a', 'b', 'C'])
|
||||
})
|
||||
|
||||
it('returns an unchanged copy for an out-of-range index', () => {
|
||||
const list = ['a', 'b']
|
||||
expect(replaceBindingAt(list, 5, 'x')).toEqual(['a', 'b'])
|
||||
expect(replaceBindingAt(list, -1, 'x')).toEqual(['a', 'b'])
|
||||
expect(replaceBindingAt(list, 5, 'x')).not.toBe(list)
|
||||
})
|
||||
|
||||
it('does not mutate the original', () => {
|
||||
const list = ['a', 'b']
|
||||
replaceBindingAt(list, 0, 'A')
|
||||
expect(list).toEqual(['a', 'b'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('removeBindingAt', () => {
|
||||
it('removes the element at the index', () => {
|
||||
expect(removeBindingAt(['a', 'b', 'c'], 1)).toEqual(['a', 'c'])
|
||||
})
|
||||
|
||||
it('removing the only element yields an empty array', () => {
|
||||
expect(removeBindingAt(['a'], 0)).toEqual([])
|
||||
})
|
||||
|
||||
it('returns an unchanged copy for an out-of-range index', () => {
|
||||
const list = ['a', 'b']
|
||||
expect(removeBindingAt(list, 5)).toEqual(['a', 'b'])
|
||||
expect(removeBindingAt(list, -1)).toEqual(['a', 'b'])
|
||||
expect(removeBindingAt(list, 5)).not.toBe(list)
|
||||
})
|
||||
|
||||
it('does not mutate the original', () => {
|
||||
const list = ['a', 'b', 'c']
|
||||
removeBindingAt(list, 0)
|
||||
expect(list).toEqual(['a', 'b', 'c'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('adjustRecordingIndexAfterRemove', () => {
|
||||
it('keeps null when nothing is recording', () => {
|
||||
expect(adjustRecordingIndexAfterRemove(null, 2)).toBeNull()
|
||||
})
|
||||
|
||||
it('clears recording when the recorded row is removed', () => {
|
||||
expect(adjustRecordingIndexAfterRemove(2, 2)).toBeNull()
|
||||
expect(adjustRecordingIndexAfterRemove(0, 0)).toBeNull()
|
||||
})
|
||||
|
||||
it('shifts the index down when a row above it is removed', () => {
|
||||
expect(adjustRecordingIndexAfterRemove(3, 1)).toBe(2)
|
||||
})
|
||||
|
||||
it('leaves the index unchanged when a row below it is removed', () => {
|
||||
expect(adjustRecordingIndexAfterRemove(1, 3)).toBe(1)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
// Pure array operations for editing one action's binding list. The override
|
||||
// model stores all of an action's bindings in a single array, so adding,
|
||||
// editing, or removing a single binding means saving a mutated copy of the
|
||||
// effective list. Kept side-effect-free (no dedupe — saveBindings/
|
||||
// normalizeKeybindingListForAction already dedupe) so they stay unit-testable.
|
||||
|
||||
export function appendBinding(list: readonly string[], binding: string): string[] {
|
||||
return [...list, binding]
|
||||
}
|
||||
|
||||
export function replaceBindingAt(
|
||||
list: readonly string[],
|
||||
index: number,
|
||||
binding: string
|
||||
): string[] {
|
||||
if (index < 0 || index >= list.length) {
|
||||
return [...list]
|
||||
}
|
||||
return list.map((existing, current) => (current === index ? binding : existing))
|
||||
}
|
||||
|
||||
export function removeBindingAt(list: readonly string[], index: number): string[] {
|
||||
if (index < 0 || index >= list.length) {
|
||||
return [...list]
|
||||
}
|
||||
return list.filter((_, current) => current !== index)
|
||||
}
|
||||
|
||||
// Keeps a pending recording aimed at the right binding after a sibling is
|
||||
// removed: the recorded row is gone (→ null), rows below it shift up by one,
|
||||
// rows above are untouched.
|
||||
export function adjustRecordingIndexAfterRemove(
|
||||
current: number | null,
|
||||
removedIndex: number
|
||||
): number | null {
|
||||
if (current === null) {
|
||||
return null
|
||||
}
|
||||
if (current === removedIndex) {
|
||||
return null
|
||||
}
|
||||
return current > removedIndex ? current - 1 : current
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import {
|
||||
isKeybindingAllowedInTerminal,
|
||||
isKeybindingPotentialTerminalConflict,
|
||||
keybindingIsActiveInContext,
|
||||
type KeybindingDefinition,
|
||||
type TerminalShortcutPolicy
|
||||
} from '../../../../shared/keybindings'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
// Describes how a shortcut behaves while a terminal/TUI has keyboard focus,
|
||||
// surfaced as a badge on the command header. Lives in its own module so the
|
||||
// command-block, filter rail, and pane can share it without importing a
|
||||
// component file.
|
||||
export type ShortcutTerminalStatus = {
|
||||
label: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export function getShortcutTerminalStatus(
|
||||
definition: KeybindingDefinition,
|
||||
terminalShortcutPolicy: TerminalShortcutPolicy,
|
||||
hasEffectiveBinding: boolean
|
||||
): ShortcutTerminalStatus | undefined {
|
||||
if (!hasEffectiveBinding) {
|
||||
return undefined
|
||||
}
|
||||
if (definition.scope === 'terminal') {
|
||||
return {
|
||||
label: translate('auto.components.settings.ShortcutsPane.cb02e00202', 'Terminal'),
|
||||
description: translate(
|
||||
'auto.components.settings.ShortcutsPane.781cb74d22',
|
||||
'Runs from terminal panes.'
|
||||
)
|
||||
}
|
||||
}
|
||||
if (isKeybindingAllowedInTerminal(definition)) {
|
||||
return {
|
||||
label: translate('auto.components.settings.ShortcutsPane.25b0004fbf', 'Terminal active'),
|
||||
description: translate(
|
||||
'auto.components.settings.ShortcutsPane.3c0fac059a',
|
||||
'Still runs while a terminal has keyboard focus.'
|
||||
)
|
||||
}
|
||||
}
|
||||
if (!isKeybindingPotentialTerminalConflict(definition)) {
|
||||
return undefined
|
||||
}
|
||||
const activeInTerminal = keybindingIsActiveInContext(definition, {
|
||||
context: 'terminal',
|
||||
terminalShortcutPolicy
|
||||
})
|
||||
return activeInTerminal
|
||||
? {
|
||||
label: translate('auto.components.settings.ShortcutsPane.2a0e8aeccf', 'Orca first'),
|
||||
description: translate(
|
||||
'auto.components.settings.ShortcutsPane.dfa8ff612f',
|
||||
'Also runs while a terminal or TUI has keyboard focus.'
|
||||
)
|
||||
}
|
||||
: {
|
||||
label: translate('auto.components.settings.ShortcutsPane.5c65d5db9d', 'Terminal first'),
|
||||
description: translate(
|
||||
'auto.components.settings.ShortcutsPane.f0b35b0b2e',
|
||||
'Disabled while a terminal or TUI has keyboard focus.'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -5848,19 +5848,6 @@
|
||||
"df38d612b7": "No projects added yet.",
|
||||
"3e483e256b": "No matching project settings."
|
||||
},
|
||||
"ShortcutBindingRow": {
|
||||
"4a4c2c9d32": "Add shortcut",
|
||||
"87381fd8f8": "Press keys…",
|
||||
"9cdaaa3d8f": "Disable shortcut",
|
||||
"3b62c142fa": "Disable {{value0}}",
|
||||
"f75335b155": "Reset to default",
|
||||
"4f2c9b2a05": "Reset {{value0}} to default",
|
||||
"97dccee14e": "Modified",
|
||||
"3b11ef3a43": "{{value0}} shortcut",
|
||||
"f6579be67b": "Change shortcut",
|
||||
"6a7848fdac": "Listening for shortcut",
|
||||
"a98d551407": "Press a shortcut, or double-tap a modifier (e.g. {{value0}}). Esc cancels."
|
||||
},
|
||||
"ShortcutFilterRail": {
|
||||
"28b63545bf": "Status",
|
||||
"8a1e78c14b": "Shortcut status filters",
|
||||
@@ -8134,6 +8121,36 @@
|
||||
"d37e92a06b": "ORCA_DIAGNOSTICS_DISABLED=1 is set — app diagnostics are off.",
|
||||
"5ebb31e1fb": "Running in CI — diagnostics are off.",
|
||||
"e27c8d45bf": "Diagnostics are disabled by an environment variable."
|
||||
},
|
||||
"ShortcutCommandBlock": {
|
||||
"eb72c52c28": "Press a shortcut, or double-tap a modifier (e.g. {{value0}}). Esc cancels.",
|
||||
"70b5d25583": "{{value0}} shortcut",
|
||||
"287e07ddde": "Modified",
|
||||
"3c83cd7d1c": "Disabled",
|
||||
"07939d084e": "Reset {{value0}} to default",
|
||||
"9b02917027": "Reset to default",
|
||||
"a799f90f82": "Disable {{value0}}",
|
||||
"25e6e76618": "Disable shortcut",
|
||||
"035a822ef0": "Add shortcut",
|
||||
"a0e2ef0e61": "Add another shortcut for {{value0}}",
|
||||
"245c83af24": "Add another shortcut",
|
||||
"482a60225d": "Enable {{value0}}",
|
||||
"6287677c37": "Enable",
|
||||
"01481b964c": "Add shortcut for {{value0}}"
|
||||
},
|
||||
"ShortcutRecorderButton": {
|
||||
"1a13bb054d": "Press shortcut keys for {{value0}}. Escape cancels.",
|
||||
"3732775d74": "Add shortcut for {{value0}}",
|
||||
"88764af2c1": "Change shortcut for {{value0}}",
|
||||
"30feb099d6": "Change shortcut {{value0}} of {{value1}} for {{value2}}",
|
||||
"5d982a2a1f": "Listening for shortcut",
|
||||
"152e0bcd64": "Add shortcut",
|
||||
"5bd56445da": "Change shortcut",
|
||||
"f5ed5dcbf6": "Press keys…"
|
||||
},
|
||||
"ShortcutRemoveButton": {
|
||||
"9e29aff18b": "Remove {{value0}} shortcut {{value1}}",
|
||||
"2a9588b1c2": "Remove this binding"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
|
||||
@@ -5811,19 +5811,6 @@
|
||||
"df38d612b7": "Aún no se han agregado proyectos.",
|
||||
"3e483e256b": "No hay configuraciones de proyecto coincidentes."
|
||||
},
|
||||
"ShortcutBindingRow": {
|
||||
"4a4c2c9d32": "Agregar acceso directo",
|
||||
"87381fd8f8": "Presione las teclas…",
|
||||
"9cdaaa3d8f": "Deshabilitar acceso directo",
|
||||
"3b62c142fa": "Deshabilitar {{value0}}",
|
||||
"f75335b155": "Restablecer los valores predeterminados",
|
||||
"4f2c9b2a05": "Restablecer {{value0}} a los valores predeterminados",
|
||||
"97dccee14e": "Modificado",
|
||||
"3b11ef3a43": "{{value0}} atajo",
|
||||
"f6579be67b": "Cambiar acceso directo",
|
||||
"6a7848fdac": "Escuchando atajos",
|
||||
"a98d551407": "Pulsa un atajo o toca dos veces una tecla modificadora (p. ej., {{value0}}). Esc cancela."
|
||||
},
|
||||
"ShortcutFilterRail": {
|
||||
"28b63545bf": "Estado",
|
||||
"8a1e78c14b": "Filtros de estado de acceso directo",
|
||||
@@ -8134,6 +8121,36 @@
|
||||
"d37e92a06b": "ORCA_DIAGNOSTICS_DISABLED=1 está configurado: los diagnósticos de la app están desactivados.",
|
||||
"5ebb31e1fb": "Se está ejecutando en CI: los diagnósticos están desactivados.",
|
||||
"e27c8d45bf": "Los diagnósticos están desactivados por una variable de entorno."
|
||||
},
|
||||
"ShortcutCommandBlock": {
|
||||
"eb72c52c28": "Press a shortcut, or double-tap a modifier (e.g. {{value0}}). Esc cancels.",
|
||||
"70b5d25583": "{{value0}} shortcut",
|
||||
"287e07ddde": "Modified",
|
||||
"3c83cd7d1c": "Disabled",
|
||||
"07939d084e": "Reset {{value0}} to default",
|
||||
"9b02917027": "Reset to default",
|
||||
"a799f90f82": "Disable {{value0}}",
|
||||
"25e6e76618": "Disable shortcut",
|
||||
"035a822ef0": "Add shortcut",
|
||||
"a0e2ef0e61": "Add another shortcut for {{value0}}",
|
||||
"245c83af24": "Add another shortcut",
|
||||
"482a60225d": "Enable {{value0}}",
|
||||
"6287677c37": "Enable",
|
||||
"01481b964c": "Add shortcut for {{value0}}"
|
||||
},
|
||||
"ShortcutRecorderButton": {
|
||||
"1a13bb054d": "Press shortcut keys for {{value0}}. Escape cancels.",
|
||||
"3732775d74": "Add shortcut for {{value0}}",
|
||||
"88764af2c1": "Change shortcut for {{value0}}",
|
||||
"30feb099d6": "Change shortcut {{value0}} of {{value1}} for {{value2}}",
|
||||
"5d982a2a1f": "Listening for shortcut",
|
||||
"152e0bcd64": "Add shortcut",
|
||||
"5bd56445da": "Change shortcut",
|
||||
"f5ed5dcbf6": "Press keys…"
|
||||
},
|
||||
"ShortcutRemoveButton": {
|
||||
"9e29aff18b": "Remove {{value0}} shortcut {{value1}}",
|
||||
"2a9588b1c2": "Remove this binding"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
|
||||
@@ -5833,19 +5833,6 @@
|
||||
"df38d612b7": "まだ追加されたプロジェクトはありません。",
|
||||
"3e483e256b": "一致するプロジェクト設定がありません。"
|
||||
},
|
||||
"ShortcutBindingRow": {
|
||||
"4a4c2c9d32": "ショートカットを追加",
|
||||
"87381fd8f8": "キーを押してください…",
|
||||
"9cdaaa3d8f": "ショートカットを無効にする",
|
||||
"3b62c142fa": "{{value0}} を無効にする",
|
||||
"f75335b155": "デフォルトにリセットする",
|
||||
"4f2c9b2a05": "{{value0}} をデフォルトにリセット",
|
||||
"97dccee14e": "修正済み",
|
||||
"3b11ef3a43": "{{value0}} ショートカット",
|
||||
"f6579be67b": "ショートカットを変更する",
|
||||
"6a7848fdac": "ショートカットを記録中",
|
||||
"a98d551407": "ショートカットを押すか、修飾キーをダブルタップしてください(例: {{value0}})。Esc でキャンセルします。"
|
||||
},
|
||||
"ShortcutFilterRail": {
|
||||
"28b63545bf": "状態",
|
||||
"8a1e78c14b": "ショートカットステータスフィルター",
|
||||
@@ -8134,6 +8121,36 @@
|
||||
"d37e92a06b": "ORCA_DIAGNOSTICS_DISABLED=1 が設定されています — アプリ診断はオフです。",
|
||||
"5ebb31e1fb": "CI で実行中です — 診断はオフです。",
|
||||
"e27c8d45bf": "環境変数により診断は無効になっています。"
|
||||
},
|
||||
"ShortcutCommandBlock": {
|
||||
"eb72c52c28": "Press a shortcut, or double-tap a modifier (e.g. {{value0}}). Esc cancels.",
|
||||
"70b5d25583": "{{value0}} shortcut",
|
||||
"287e07ddde": "Modified",
|
||||
"3c83cd7d1c": "Disabled",
|
||||
"07939d084e": "Reset {{value0}} to default",
|
||||
"9b02917027": "Reset to default",
|
||||
"a799f90f82": "Disable {{value0}}",
|
||||
"25e6e76618": "Disable shortcut",
|
||||
"035a822ef0": "Add shortcut",
|
||||
"a0e2ef0e61": "Add another shortcut for {{value0}}",
|
||||
"245c83af24": "Add another shortcut",
|
||||
"482a60225d": "Enable {{value0}}",
|
||||
"6287677c37": "Enable",
|
||||
"01481b964c": "Add shortcut for {{value0}}"
|
||||
},
|
||||
"ShortcutRecorderButton": {
|
||||
"1a13bb054d": "Press shortcut keys for {{value0}}. Escape cancels.",
|
||||
"3732775d74": "Add shortcut for {{value0}}",
|
||||
"88764af2c1": "Change shortcut for {{value0}}",
|
||||
"30feb099d6": "Change shortcut {{value0}} of {{value1}} for {{value2}}",
|
||||
"5d982a2a1f": "Listening for shortcut",
|
||||
"152e0bcd64": "Add shortcut",
|
||||
"5bd56445da": "Change shortcut",
|
||||
"f5ed5dcbf6": "Press keys…"
|
||||
},
|
||||
"ShortcutRemoveButton": {
|
||||
"9e29aff18b": "Remove {{value0}} shortcut {{value1}}",
|
||||
"2a9588b1c2": "Remove this binding"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
|
||||
@@ -5796,19 +5796,6 @@
|
||||
"df38d612b7": "아직 추가된 프로젝트가 없습니다.",
|
||||
"3e483e256b": "일치하는 프로젝트 설정이 없습니다."
|
||||
},
|
||||
"ShortcutBindingRow": {
|
||||
"4a4c2c9d32": "바로가기 추가",
|
||||
"87381fd8f8": "키를 누르세요…",
|
||||
"9cdaaa3d8f": "바로가기 비활성화",
|
||||
"3b62c142fa": "{{value0}} 비활성화",
|
||||
"f75335b155": "기본값으로 재설정",
|
||||
"4f2c9b2a05": "{{value0}}을 기본값으로 재설정",
|
||||
"97dccee14e": "수정됨",
|
||||
"3b11ef3a43": "{{value0}} 바로가기",
|
||||
"f6579be67b": "바로가기 변경",
|
||||
"6a7848fdac": "단축키 입력 대기 중",
|
||||
"a98d551407": "단축키를 누르거나 보조 키를 두 번 탭하세요(예: {{value0}}). Esc로 취소합니다."
|
||||
},
|
||||
"ShortcutFilterRail": {
|
||||
"28b63545bf": "상태",
|
||||
"8a1e78c14b": "바로가기 상태 필터",
|
||||
@@ -8134,6 +8121,36 @@
|
||||
"d37e92a06b": "ORCA_DIAGNOSTICS_DISABLED=1이 설정되어 있어 앱 진단이 꺼져 있습니다.",
|
||||
"5ebb31e1fb": "CI에서 실행 중입니다. 진단이 꺼져 있습니다.",
|
||||
"e27c8d45bf": "환경 변수로 인해 진단이 비활성화되었습니다."
|
||||
},
|
||||
"ShortcutCommandBlock": {
|
||||
"eb72c52c28": "Press a shortcut, or double-tap a modifier (e.g. {{value0}}). Esc cancels.",
|
||||
"70b5d25583": "{{value0}} shortcut",
|
||||
"287e07ddde": "Modified",
|
||||
"3c83cd7d1c": "Disabled",
|
||||
"07939d084e": "Reset {{value0}} to default",
|
||||
"9b02917027": "Reset to default",
|
||||
"a799f90f82": "Disable {{value0}}",
|
||||
"25e6e76618": "Disable shortcut",
|
||||
"035a822ef0": "Add shortcut",
|
||||
"a0e2ef0e61": "Add another shortcut for {{value0}}",
|
||||
"245c83af24": "Add another shortcut",
|
||||
"482a60225d": "Enable {{value0}}",
|
||||
"6287677c37": "Enable",
|
||||
"01481b964c": "Add shortcut for {{value0}}"
|
||||
},
|
||||
"ShortcutRecorderButton": {
|
||||
"1a13bb054d": "Press shortcut keys for {{value0}}. Escape cancels.",
|
||||
"3732775d74": "Add shortcut for {{value0}}",
|
||||
"88764af2c1": "Change shortcut for {{value0}}",
|
||||
"30feb099d6": "Change shortcut {{value0}} of {{value1}} for {{value2}}",
|
||||
"5d982a2a1f": "Listening for shortcut",
|
||||
"152e0bcd64": "Add shortcut",
|
||||
"5bd56445da": "Change shortcut",
|
||||
"f5ed5dcbf6": "Press keys…"
|
||||
},
|
||||
"ShortcutRemoveButton": {
|
||||
"9e29aff18b": "Remove {{value0}} shortcut {{value1}}",
|
||||
"2a9588b1c2": "Remove this binding"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
|
||||
@@ -5796,19 +5796,6 @@
|
||||
"df38d612b7": "尚未添加项目。",
|
||||
"3e483e256b": "没有匹配的项目设置。"
|
||||
},
|
||||
"ShortcutBindingRow": {
|
||||
"4a4c2c9d32": "添加快捷方式",
|
||||
"87381fd8f8": "按键...",
|
||||
"9cdaaa3d8f": "禁用快捷方式",
|
||||
"3b62c142fa": "禁用 {{value0}}",
|
||||
"f75335b155": "重置为默认值",
|
||||
"4f2c9b2a05": "将 {{value0}} 重置为默认值",
|
||||
"97dccee14e": "修改的",
|
||||
"3b11ef3a43": "{{value0}} 快捷方式",
|
||||
"f6579be67b": "更改快捷方式",
|
||||
"6a7848fdac": "正在录制快捷键",
|
||||
"a98d551407": "按下快捷键,或双击一个修饰键(例如 {{value0}})。按 Esc 取消。"
|
||||
},
|
||||
"ShortcutFilterRail": {
|
||||
"28b63545bf": "状态",
|
||||
"8a1e78c14b": "快捷状态搜索器",
|
||||
@@ -8134,6 +8121,36 @@
|
||||
"d37e92a06b": "已设置 ORCA_DIAGNOSTICS_DISABLED=1,应用诊断已关闭。",
|
||||
"5ebb31e1fb": "正在 CI 中运行,诊断已关闭。",
|
||||
"e27c8d45bf": "诊断已被环境变量停用。"
|
||||
},
|
||||
"ShortcutCommandBlock": {
|
||||
"eb72c52c28": "Press a shortcut, or double-tap a modifier (e.g. {{value0}}). Esc cancels.",
|
||||
"70b5d25583": "{{value0}} shortcut",
|
||||
"287e07ddde": "Modified",
|
||||
"3c83cd7d1c": "Disabled",
|
||||
"07939d084e": "Reset {{value0}} to default",
|
||||
"9b02917027": "Reset to default",
|
||||
"a799f90f82": "Disable {{value0}}",
|
||||
"25e6e76618": "Disable shortcut",
|
||||
"035a822ef0": "Add shortcut",
|
||||
"a0e2ef0e61": "Add another shortcut for {{value0}}",
|
||||
"245c83af24": "Add another shortcut",
|
||||
"482a60225d": "Enable {{value0}}",
|
||||
"6287677c37": "Enable",
|
||||
"01481b964c": "Add shortcut for {{value0}}"
|
||||
},
|
||||
"ShortcutRecorderButton": {
|
||||
"1a13bb054d": "Press shortcut keys for {{value0}}. Escape cancels.",
|
||||
"3732775d74": "Add shortcut for {{value0}}",
|
||||
"88764af2c1": "Change shortcut for {{value0}}",
|
||||
"30feb099d6": "Change shortcut {{value0}} of {{value1}} for {{value2}}",
|
||||
"5d982a2a1f": "Listening for shortcut",
|
||||
"152e0bcd64": "Add shortcut",
|
||||
"5bd56445da": "Change shortcut",
|
||||
"f5ed5dcbf6": "Press keys…"
|
||||
},
|
||||
"ShortcutRemoveButton": {
|
||||
"9e29aff18b": "Remove {{value0}} shortcut {{value1}}",
|
||||
"2a9588b1c2": "Remove this binding"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
|
||||
Reference in New Issue
Block a user