mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix(composer): reverse arrow navigation for the mobile takeover list
In takeover mode the suggestion rows render reversed so the best match sits nearest the composer. Stepping the selection in index order moved it opposite the pressed arrow on mobile; flip the step when isMobile while preserving desktop clamp and wrap behavior.
This commit is contained in:
1 parent
855b78297e
commit
a566610c66
3 files changed
+124
-8
No files matched your search
@@ -36,6 +36,8 @@ const mocks = vi.hoisted(() => ({
|
||||
useSendErrorStore: vi.fn(),
|
||||
}))
|
||||
|
||||
const suggestionProps = vi.hoisted(() => ({ isOpen: false, selectedIndex: 0 }))
|
||||
|
||||
vi.mock('@/api/opencode', async () => {
|
||||
const actual = await vi.importActual('@/api/opencode')
|
||||
return {
|
||||
@@ -106,7 +108,13 @@ vi.mock('./ComposerToolsMenu', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('./PromptSuggestions', () => ({
|
||||
PromptSuggestions: () => null,
|
||||
PromptSuggestions: (props: { isOpen: boolean; selectedIndex: number }) => {
|
||||
if (props.isOpen) {
|
||||
suggestionProps.isOpen = true
|
||||
suggestionProps.selectedIndex = props.selectedIndex
|
||||
}
|
||||
return null
|
||||
},
|
||||
}))
|
||||
|
||||
const createTestQueryClient = () => new QueryClient({
|
||||
@@ -199,6 +207,8 @@ describe('PromptInput command submission', () => {
|
||||
mocks.useUserBash.mockImplementation((selector: (state: unknown) => unknown) => selector({ addUserBashCommand: vi.fn() }))
|
||||
mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: mocks.setAgent }))
|
||||
mocks.useSendErrorStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ errors: {} }))
|
||||
suggestionProps.isOpen = false
|
||||
suggestionProps.selectedIndex = 0
|
||||
useUIState.getState().clearPendingPromptCommand()
|
||||
useUIState.getState().clearPendingPromptFile()
|
||||
})
|
||||
@@ -440,6 +450,51 @@ describe('PromptInput command submission', () => {
|
||||
expect(mocks.showToast.info).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
const commandSuggestions = () => ({
|
||||
searchCommands: () => [
|
||||
{ item: { name: 'alpha', description: 'Alpha' }, ranges: [] },
|
||||
{ item: { name: 'beta', description: 'Beta' }, ranges: [] },
|
||||
{ item: { name: 'gamma', description: 'Gamma' }, ranges: [] },
|
||||
],
|
||||
findCommand: () => undefined,
|
||||
recentNames: [],
|
||||
})
|
||||
|
||||
it('moves the command selection in the visual direction of the arrow on mobile', async () => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
mocks.useCommands.mockReturnValue(commandSuggestions())
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '/', selectionStart: 1 } })
|
||||
|
||||
await waitFor(() => expect(suggestionProps.isOpen).toBe(true))
|
||||
expect(suggestionProps.selectedIndex).toBe(0)
|
||||
|
||||
fireEvent.keyDown(input, { key: 'ArrowUp' })
|
||||
await waitFor(() => expect(suggestionProps.selectedIndex).toBe(1))
|
||||
|
||||
fireEvent.keyDown(input, { key: 'ArrowDown' })
|
||||
await waitFor(() => expect(suggestionProps.selectedIndex).toBe(0))
|
||||
})
|
||||
|
||||
it('keeps the desktop command arrow direction unchanged', async () => {
|
||||
mocks.useCommands.mockReturnValue(commandSuggestions())
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '/', selectionStart: 1 } })
|
||||
|
||||
await waitFor(() => expect(suggestionProps.isOpen).toBe(true))
|
||||
expect(suggestionProps.selectedIndex).toBe(0)
|
||||
|
||||
fireEvent.keyDown(input, { key: 'ArrowDown' })
|
||||
await waitFor(() => expect(suggestionProps.selectedIndex).toBe(1))
|
||||
|
||||
fireEvent.keyDown(input, { key: 'ArrowUp' })
|
||||
await waitFor(() => expect(suggestionProps.selectedIndex).toBe(0))
|
||||
})
|
||||
|
||||
describe('mobile keybar', () => {
|
||||
beforeEach(() => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
|
||||
@@ -24,6 +24,8 @@ const mocks = vi.hoisted(() => ({
|
||||
useSendErrorStore: vi.fn(),
|
||||
}))
|
||||
|
||||
const suggestionProps = vi.hoisted(() => ({ isOpen: false, selectedIndex: 0 }))
|
||||
|
||||
vi.mock('@/api/opencode', async () => {
|
||||
const actual = await vi.importActual('@/api/opencode')
|
||||
return {
|
||||
@@ -93,7 +95,17 @@ vi.mock('@/components/ui/session-status-indicator', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('./PromptSuggestions', () => ({
|
||||
PromptSuggestions: () => null,
|
||||
PromptSuggestions: (props: { isOpen: boolean; selectedIndex: number }) => {
|
||||
if (props.isOpen) {
|
||||
suggestionProps.isOpen = true
|
||||
suggestionProps.selectedIndex = props.selectedIndex
|
||||
}
|
||||
return null
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('./ComposerToolsMenu', () => ({
|
||||
ComposerToolsMenu: () => null,
|
||||
}))
|
||||
|
||||
const createTestQueryClient = () => new QueryClient({
|
||||
@@ -180,6 +192,8 @@ describe('PromptInput agent mention submission', () => {
|
||||
mocks.useSessionAgent.mockReturnValue({ agent: 'build' })
|
||||
mocks.useUserBash.mockImplementation((selector: (state: unknown) => unknown) => selector({ addUserBashCommand: vi.fn() }))
|
||||
mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: vi.fn() }))
|
||||
suggestionProps.isOpen = false
|
||||
suggestionProps.selectedIndex = 0
|
||||
useUIState.getState().clearPendingPromptCommand()
|
||||
useUIState.getState().clearPendingPromptFile()
|
||||
})
|
||||
@@ -253,4 +267,45 @@ describe('PromptInput agent mention submission', () => {
|
||||
expect(mocks.switchSessionAgent).not.toHaveBeenCalled()
|
||||
expect(mocks.switchSessionModel).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('moves the mention selection in the visual direction of the arrow on mobile', async () => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
mocks.agents = [
|
||||
{ name: 'alpha', description: 'Alpha agent' },
|
||||
{ name: 'beta', description: 'Beta agent' },
|
||||
]
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '@', selectionStart: 1 } })
|
||||
|
||||
await waitFor(() => expect(suggestionProps.isOpen).toBe(true))
|
||||
expect(suggestionProps.selectedIndex).toBe(0)
|
||||
|
||||
fireEvent.keyDown(input, { key: 'ArrowUp' })
|
||||
await waitFor(() => expect(suggestionProps.selectedIndex).toBe(1))
|
||||
|
||||
fireEvent.keyDown(input, { key: 'ArrowDown' })
|
||||
await waitFor(() => expect(suggestionProps.selectedIndex).toBe(0))
|
||||
})
|
||||
|
||||
it('keeps the desktop arrow direction unchanged', async () => {
|
||||
mocks.agents = [
|
||||
{ name: 'alpha', description: 'Alpha agent' },
|
||||
{ name: 'beta', description: 'Beta agent' },
|
||||
]
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '@', selectionStart: 1 } })
|
||||
|
||||
await waitFor(() => expect(suggestionProps.isOpen).toBe(true))
|
||||
expect(suggestionProps.selectedIndex).toBe(0)
|
||||
|
||||
fireEvent.keyDown(input, { key: 'ArrowUp' })
|
||||
expect(suggestionProps.selectedIndex).toBe(0)
|
||||
|
||||
fireEvent.keyDown(input, { key: 'ArrowDown' })
|
||||
await waitFor(() => expect(suggestionProps.selectedIndex).toBe(1))
|
||||
})
|
||||
})
|
||||
@@ -1030,18 +1030,24 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
return
|
||||
}
|
||||
|
||||
const suggestionStep = isMobile ? -1 : 1
|
||||
|
||||
if (showMentionSuggestions && mentionSuggestions.length > 0) {
|
||||
if (e.key === 'ArrowDown') {
|
||||
e.preventDefault()
|
||||
setSelectedMentionIndex(prev =>
|
||||
prev < mentionSuggestions.length - 1 ? prev + 1 : prev
|
||||
)
|
||||
setSelectedMentionIndex(prev => {
|
||||
const next = prev + suggestionStep
|
||||
return next >= 0 && next < mentionSuggestions.length ? next : prev
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (e.key === 'ArrowUp') {
|
||||
e.preventDefault()
|
||||
setSelectedMentionIndex(prev => prev > 0 ? prev - 1 : 0)
|
||||
setSelectedMentionIndex(prev => {
|
||||
const next = prev - suggestionStep
|
||||
return next >= 0 && next < mentionSuggestions.length ? next : prev
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1066,13 +1072,13 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
if (showSuggestions) {
|
||||
if (e.key === 'ArrowDown' && commandSuggestions.length > 0) {
|
||||
e.preventDefault()
|
||||
setSelectedCommandIndex(prev => (prev + 1) % commandSuggestions.length)
|
||||
setSelectedCommandIndex(prev => (prev + suggestionStep + commandSuggestions.length) % commandSuggestions.length)
|
||||
return
|
||||
}
|
||||
|
||||
if (e.key === 'ArrowUp' && commandSuggestions.length > 0) {
|
||||
e.preventDefault()
|
||||
setSelectedCommandIndex(prev => (prev - 1 + commandSuggestions.length) % commandSuggestions.length)
|
||||
setSelectedCommandIndex(prev => (prev - suggestionStep + commandSuggestions.length) % commandSuggestions.length)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user