Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix: 本地快捷键不看 defaultPrevented,序号文字保留给读屏

Dashcc8af3cb13d2
diff --git a/apps/desktop/src/renderer/__tests__/askUserQuestionVoice.test.tsx b/apps/desktop/src/renderer/__tests__/askUserQuestionVoice.test.tsx
index 743588d184..5185ecce09 100644
--- a/apps/desktop/src/renderer/__tests__/askUserQuestionVoice.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/askUserQuestionVoice.test.tsx
@@ -85,13 +85,23 @@ describe('AskUserQuestion voice entry', () => {
expect(badge.parentElement).toBe(voice.parentElement);
expect(badge.parentElement!.lastElementChild).toBe(badge);
expect(voice.compareDocumentPosition(badge) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
- expect(view.getByRole('button', { name: '输入其他回答…' })).toBeTruthy();
+ expect(view.getByRole('button', { name: /输入其他回答…/ })).toBeTruthy();
fireEvent.click(badge);
expect(view.getByPlaceholderText('请输入回答…')).toBeTruthy();
expect(start).not.toHaveBeenCalled();
});
+ it('keeps the free-text number in the row button for screen readers', () => {
+ const { view } = renderAsk([
+ { question: '选哪个?', options: [{ label: '甲' }, { label: '乙' }] },
+ ]);
+ const row = view.getByRole('button', { name: /输入其他回答…/ });
+ expect(row.textContent).toContain('3');
+ expect(row.querySelector('.sr-only')?.textContent).toBe('3');
+ expect(view.getByTestId('ask-user-custom-badge').getAttribute('aria-hidden')).toBe('true');
+ });
+
it('keeps the voice button in the same bottom-pinned cluster as the send button', () => {
const { view } = renderAsk([
{ question: '选哪个?', options: [{ label: '甲' }, { label: '乙' }] },
@@ -335,7 +345,7 @@ describe('voice shortcut ownership across cards', () => {
it('still gives the press to a focused worker card over the Orca lead card', async () => {
const { view, voiceIn } = renderPanes(['expanded', 'expanded'], 0);
- within(view.getByTestId('pane-1')).getByRole('button', { name: '输入其他回答…' }).focus();
+ within(view.getByTestId('pane-1')).getByRole('button', { name: /输入其他回答…/ }).focus();
await press({ id: 'p1', phase: 'start' });
await waitFor(() => expect(start).toHaveBeenCalledOnce());
@@ -345,7 +355,7 @@ describe('voice shortcut ownership across cards', () => {
it('follows keyboard focus to an older card', async () => {
const { view, voiceIn } = renderPanes();
- within(view.getByTestId('pane-0')).getByRole('button', { name: '输入其他回答…' }).focus();
+ within(view.getByTestId('pane-0')).getByRole('button', { name: /输入其他回答…/ }).focus();
await press({ id: 'p1', phase: 'start' });
await waitFor(() => expect(start).toHaveBeenCalledOnce());
@@ -353,6 +363,30 @@ describe('voice shortcut ownership across cards', () => {
expect(voiceIn(1).getAttribute('aria-pressed')).toBe('false');
});
+ it('still acts on a local key press that a sibling composer already prevented', async () => {
+ const previous = window.electronAPI;
+ window.electronAPI = {
+ ...previous,
+ voiceInput: { ...previous.voiceInput, getDataSnapshot: () => ({ settings: { shortcut: { code: 'F9', key: 'F9', modifiers: { meta: false, ctrl: false, alt: false, shift: false, fn: false } } } }) },
+ } as unknown as typeof window.electronAPI;
+ // Registered before the cards mount, like a composer in an earlier pane:
+ // it runs first and prevents the default for every matching press.
+ const siblingComposer = (event: Event) => event.preventDefault();
+ window.addEventListener('keydown', siblingComposer, true);
+ try {
+ const { view, voiceIn } = renderPanes();
+ const focused = within(view.getByTestId('pane-0')).getByRole('button', { name: /输入其他回答…/ });
+ focused.focus();
+ await act(async () => {
+ focused.dispatchEvent(new KeyboardEvent('keydown', { key: 'F9', code: 'F9', bubbles: true, cancelable: true }));
+ });
+ expect(voiceIn(0).getAttribute('aria-pressed')).toBe('true');
+ } finally {
+ window.removeEventListener('keydown', siblingComposer, true);
+ window.electronAPI = previous;
+ }
+ });
+
it('leaves the press unclaimed when another text field has focus', async () => {
const { view } = renderPanes();
view.getByTestId('sidebar-search').focus();
diff --git a/apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx b/apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx
index 2034dc7e6d..77c68fcc69 100644
--- a/apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx
@@ -554,9 +554,12 @@ function AskUserQuestionForm({
beginVoiceInput();
};
const onKeyDown = (event: KeyboardEvent) => {
- if (event.repeat || event.isComposing || event.defaultPrevented) return;
+ if (event.repeat || event.isComposing) return;
const shortcut = getVoiceInputSettings().shortcut;
if (!isVoiceInputShortcutMatch(event, shortcut)) return;
+ // No defaultPrevented check: an unfocused sibling composer swallows every
+ // matching press to keep it out of other inputs, so that flag says nothing
+ // about who should act. Ownership alone decides.
if (!shortcutCard.owns(event.target)) return;
event.preventDefault();
event.stopPropagation();
@@ -942,10 +945,13 @@ function AskUserQuestionForm({
<span className="text-14 italic text-[var(--ask-option-custom)]">
{t('chat.askUserQuestion.customAnswer')}
</span>
+ {/* The visible badge moved out of the button; keep its number in the
+ button for screen readers, as the option rows do. */}
+ <span className="sr-only">{options.length + 1}</span>
</button>
{!voiceBridge && (<AskUserVoiceButton label={voiceButtonLabel} busy={dictation.isBusy} onClick={beginVoiceInput} />)}
- {/* Pointer shortcut only: the row button above and the number key
- already give keyboard and screen-reader users this action. */}
+ {/* Pointer shortcut only: the row button above already carries the
+ action and its number for keyboard and screen-reader users. */}
<div
aria-hidden="true"
data-testid="ask-user-custom-badge"