mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(shortcuts): add favorite model cycle shortcut (Ctrl+R)
This commit is contained in:
1 parent
994a8b82e8
commit
e89b782fef
7 files changed
+71
-5
No files matched your search
@@ -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])
|
||||
})
|
||||
})
|
||||
@@ -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]
|
||||
}
|
||||
@@ -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'],
|
||||
|
||||
Reference in new issue
Block a user