fix: preserve agent task editor focus when inserting commands (#41166)

This commit is contained in:
Joel 2026-08-24 08:33:29 +00:00 committed by GitHub
parent 3de20e0ba8
commit fef28097cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import type { AgentV2NodeType } from '../types'
import type { PromptEditorProps } from '@/app/components/base/prompt-editor'
import type { NodePanelProps } from '@/app/components/workflow/types'
import { act, fireEvent, render, screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { BlockEnum } from '@/app/components/workflow/types'
import { FlowType } from '@/types/common'
import { AgentV2Panel } from '../panel'
@ -1230,7 +1231,8 @@ describe('agent/panel', () => {
expect(screen.queryByText('Clarification Drafter')).not.toBeInTheDocument()
})
it('updates agent task and opens prompt insertion shortcuts', () => {
it('updates agent task and opens prompt insertion shortcuts', async () => {
const user = userEvent.setup()
render(
<AgentV2Panel
id="agent-node"
@ -1267,9 +1269,9 @@ describe('agent/panel', () => {
screen.queryByRole('button', { name: 'workflow.nodes.agent.task.mention' }),
).not.toBeInTheDocument()
fireEvent.focus(editor)
await user.click(editor)
fireEvent.click(screen.getByRole('button', { name: 'workflow.nodes.agent.task.insert' }))
await user.click(screen.getByRole('button', { name: 'workflow.nodes.agent.task.insert' }))
expect(mockEditorFocus).toHaveBeenCalled()
expect(mockInsertNodes.mock.calls[0]?.[0]?.[0]?.getTextContent()).toBe('/')
expect(

View File

@ -36,6 +36,7 @@ function AgentTaskToolbar({ taskLength, onInsert }: { taskLength: number; onInse
<button
type="button"
className="flex items-center gap-1 system-xs-medium hover:text-text-secondary focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"
onMouseDown={(event) => event.preventDefault()}
onClick={handleInsert}
>
<span aria-hidden className="i-ri-slash-commands-2 size-3.5" />