feat(shortcuts): add favorite model cycle shortcut (Ctrl+R)

This commit is contained in:
Chris Scott committed 2026-10-08 14:26:41 -04:00
1 parent 994a8b82e8
commit e89b782fef
7 files changed
+71 -5

No files matched your search

@@ -34,9 +34,10 @@ import { useSessionPermissionMode } from '@/hooks/useSessionPermissionMode'
import { detectMentionTrigger, parsePromptToInput, getFilename, getDirectory, type MentionItem } from '@/lib/promptParser'
import { matchText, rankByMatch, type MatchRange } from '@/lib/fuzzyMatch'
import { getNextPrimaryAgentId } from '@/lib/primaryAgents'
import { getNextFavoriteModel } from '@/lib/favoriteModels'
import { randomId } from '@/lib/utils'
import { showToast } from '@/lib/toast'
import { findModelInfo } from '@opencode-manager/shared/opencode'
import { findModelInfo, isSameModelSelection } from '@opencode-manager/shared/opencode'
import { isOpenSessionGoal } from '@opencode-manager/shared/schemas'
import { useProviders } from '@/hooks/useProviders'
@@ -112,6 +113,7 @@ export interface PromptInputHandle {
openModelPicker: () => void
cycleAgent: () => void
cycleVariant: () => void
cycleFavoriteModel: () => void
}
interface PromptInputProps {
@@ -1229,7 +1231,7 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
[sessionID, sessionAgent.sessionAgentId, sessionAgent.modelRef],
)
const { model, modelString, modelRef, setActiveAgent, isModelReady } = useModelSelection(directory, modelSelectionSession)
const { model, modelString, modelRef, favoriteModels, setModel, setActiveAgent, isModelReady } = useModelSelection(directory, modelSelectionSession)
useEffect(() => {
setActiveAgent({
@@ -1266,6 +1268,18 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
cycleVariant()
}, [hasVariants, cycleVariant])
const handleCycleFavoriteModel = useCallback(() => {
const next = getNextFavoriteModel(favoriteModels, model)
if (!next) {
showToast.info('No favorite models')
return
}
if (model && isSameModelSelection(model, next)) {
return
}
setModel(next)
}, [favoriteModels, model, setModel])
const handleCycleAgent = useCallback(() => {
const next = getNextPrimaryAgentId(agents, currentMode)
if (!next) {
@@ -1290,7 +1304,8 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
},
cycleAgent: handleCycleAgent,
cycleVariant: handleCycleVariant,
}), [resetPrompt, openFilePicker, handleCycleAgent, handleCycleVariant])
cycleFavoriteModel: handleCycleFavoriteModel,
}), [resetPrompt, openFilePicker, handleCycleAgent, handleCycleVariant, handleCycleFavoriteModel])
const commandActionsWithPrompt = useMemo<CommandActions>(
() => ({
@@ -7,7 +7,7 @@ import { formatEventModifiers, formatShortcutEvent, isModifierOnlyEvent, normali
import { applyTuiKeybindImport, parseTuiKeybindConfig } from '@/lib/tuiKeybindImport'
import { showToast } from '@/lib/toast'
const CONVERSATION_ACTIONS = ['submit', 'abort', 'clearPrompt', 'toggleMode', 'undo', 'redo', 'compact', 'fork', 'timeline', 'exportSession', 'selectModel', 'variantCycle', 'halfPageUp', 'halfPageDown']
const CONVERSATION_ACTIONS = ['submit', 'abort', 'clearPrompt', 'toggleMode', 'undo', 'redo', 'compact', 'fork', 'timeline', 'exportSession', 'selectModel', 'variantCycle', 'favoriteCycle', 'halfPageUp', 'halfPageDown']
const NAVIGATION_ACTIONS = ['settings', 'sessions', 'newSession', 'closeSession', 'toggleSidebar', 'toggleTerminal', 'toggleSourceControl']
const formatShortcutLabel = (action: string): string => {
+32
View File
@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest'
import { getNextFavoriteModel } from './favoriteModels'
import type { ModelSelection } from '@/api/providers'
const model = (providerID: string, modelID: string): ModelSelection => ({ providerID, modelID })
describe('getNextFavoriteModel', () => {
it('returns undefined when there are no favorites', () => {
expect(getNextFavoriteModel([], model('anthropic', 'claude-sonnet-4'))).toBeUndefined()
})
it('returns the first favorite when nothing is selected', () => {
const favorites = [model('anthropic', 'claude-sonnet-4'), model('openai', 'gpt-5')]
expect(getNextFavoriteModel(favorites, null)).toEqual(favorites[0])
})
it('returns the first favorite when the current model is not a favorite', () => {
const favorites = [model('anthropic', 'claude-sonnet-4'), model('openai', 'gpt-5')]
expect(getNextFavoriteModel(favorites, model('opencode-go', 'go-1'))).toEqual(favorites[0])
})
it('returns the next favorite in the middle of the list', () => {
const favorites = [model('a', 'x'), model('b', 'y'), model('c', 'z')]
expect(getNextFavoriteModel(favorites, favorites[0])).toEqual(favorites[1])
expect(getNextFavoriteModel(favorites, favorites[1])).toEqual(favorites[2])
})
it('wraps around from the last favorite to the first', () => {
const favorites = [model('a', 'x'), model('b', 'y'), model('c', 'z')]
expect(getNextFavoriteModel(favorites, favorites[2])).toEqual(favorites[0])
})
})
+15
View File
@@ -0,0 +1,15 @@
import { isSameModelSelection } from '@opencode-manager/shared/opencode'
import type { ModelSelection } from '@/api/providers'
export function getNextFavoriteModel(
favorites: readonly ModelSelection[],
current: ModelSelection | null,
): ModelSelection | undefined {
if (favorites.length === 0) return undefined
if (!current) return favorites[0]
const index = favorites.findIndex((favorite) => isSameModelSelection(favorite, current))
if (index === -1) return favorites[0]
return favorites[(index + 1) % favorites.length]
}
+2
View File
@@ -35,6 +35,7 @@ const ACTION_BY_TUI_NAME = new Map<string, KeyboardShortcutAction>([
['prompt.clear', 'clearPrompt'],
['agent.cycle', 'toggleMode'],
['variant.cycle', 'variantCycle'],
['model.cycle_favorite', 'favoriteCycle'],
['session.undo', 'undo'],
['session.redo', 'redo'],
['session.compact', 'compact'],
@@ -58,6 +59,7 @@ const ACTION_BY_LEGACY_NAME = new Map<string, KeyboardShortcutAction>([
['input_clear', 'clearPrompt'],
['agent_cycle', 'toggleMode'],
['variant_cycle', 'variantCycle'],
['model_cycle_favorite', 'favoriteCycle'],
['messages_undo', 'undo'],
['messages_redo', 'redo'],
['session_compact', 'compact'],
+1
View File
@@ -606,6 +606,7 @@ export function SessionDetail() {
exportSession: handleExportSession,
toggleMode: () => promptInputRef.current?.cycleAgent(),
variantCycle: () => promptInputRef.current?.cycleVariant(),
favoriteCycle: () => promptInputRef.current?.cycleFavoriteModel(),
submit: () => document.querySelector<HTMLButtonElement>("[data-submit-prompt]")?.click(),
abort: isSessionActive ? handleInterruptSession : undefined,
clearPrompt: handleClearPrompt,
+2 -1
View File
@@ -81,6 +81,7 @@ export const DEFAULT_KEYBOARD_SHORTCUTS = {
toggleSidebar: 'B',
selectModel: 'M',
variantCycle: 'Ctrl+T',
favoriteCycle: 'Ctrl+R',
toggleTerminal: 'T',
toggleSourceControl: '',
timeline: 'G',
@@ -91,7 +92,7 @@ export const DEFAULT_KEYBOARD_SHORTCUTS = {
export type KeyboardShortcutAction = keyof typeof DEFAULT_KEYBOARD_SHORTCUTS;
export const DEFAULT_DIRECT_SHORTCUTS = ['submit', 'abort', 'clearPrompt', 'toggleMode', 'variantCycle', 'halfPageUp', 'halfPageDown'];
export const DEFAULT_DIRECT_SHORTCUTS = ['submit', 'abort', 'clearPrompt', 'toggleMode', 'variantCycle', 'favoriteCycle', 'halfPageUp', 'halfPageDown'];
export const GitCredentialSchema = z.object({
id: z.string().optional(),