Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 修复工作中插话快捷键竞态 (#573)
Kmny3084e8f726fe
diff --git a/apps/desktop/src/renderer/__tests__/chatInputSteerShortcut.test.ts b/apps/desktop/src/renderer/__tests__/chatInputSteerShortcut.test.tsindex 8ca3637ce3..edd1e91741 100644--- a/apps/desktop/src/renderer/__tests__/chatInputSteerShortcut.test.ts+++ b/apps/desktop/src/renderer/__tests__/chatInputSteerShortcut.test.ts@@ -23,11 +23,20 @@ describe('ChatInput steer shortcut contract', () => {'// Plain Enter keeps the existing queue semantics.','return true;\n }\n return false;',);+ const windowComposerSteerBlock = extractBetween(+ windowKeydownBlock,+ 'if (\n showStopButtonRef.current &&',+ "if (\n currentState === 'listening'",+ );+ const editorSteerChoice = extractBetween(+ editorEnterBlock,+ 'const wantsSteer =',+ "void dispatchSendRef.current(wantsSteer ? 'steer' : 'queue');",+ );expect(chatInputSource).toContain('const composerCanSubmitRef = useRef(false);');expect(chatInputSource).toContain('composerCanSubmitRef.current = !sendButtonDisabled;');expect(windowKeydownBlock).toContain('showStopButtonRef.current');- expect(windowKeydownBlock).toContain('composerCanSubmitRef.current');expect(windowKeydownBlock).toContain('isComposerEnterTarget(event.target)');expect(windowKeydownBlock).toContain("event.key === 'Enter'");expect(windowKeydownBlock).toContain('event.metaKey || event.ctrlKey');@@ -39,11 +48,15 @@ describe('ChatInput steer shortcut contract', () => {expect(chatInputSource).toContain('turnRunning={showStopButton}');expect(chatInputSource).toContain('onSteer={onQueueSteer ? handleQueueSteer : undefined}');expect(editorEnterBlock).toContain("event.key === 'Enter' && !event.shiftKey && !event.altKey");- expect(editorEnterBlock).toContain('composerCanSubmitRef.current');expect(editorEnterBlock).toContain("voiceInputStateRef.current !== 'listening'");expect(editorEnterBlock).toContain("void dispatchSendRef.current(wantsSteer ? 'steer' : 'queue');",);+ // Tiptap's document is current before React's send-button effect updates+ // composerCanSubmitRef. The shortcut must not use that lagging UI mirror+ // to choose between steer and normal queue delivery.+ expect(windowComposerSteerBlock).not.toContain('composerCanSubmitRef.current');+ expect(editorSteerChoice).not.toContain('composerCanSubmitRef.current');});it('steers without an interrupt confirmation gate (same-turn injection)', () => {diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 1d091f8d42..c61cfea10c 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -1974,10 +1974,14 @@ export function ChatInput({void voiceInputStopAndSendRef.current(deliveryMode);return true;}+ // Do not gate the delivery choice on composerCanSubmitRef here.+ // Tiptap updates its document synchronously, while that ref mirrors+ // sendButtonDisabled from a later React effect. A quick Cmd/Ctrl+Enter+ // after typing could otherwise observe the previous empty state and+ // incorrectly enqueue instead of steering the running turn.const wantsSteer =(event.metaKey || event.ctrlKey) &&showStopButtonRef.current &&- composerCanSubmitRef.current &&voiceInputStateRef.current !== 'listening';void dispatchSendRef.current(wantsSteer ? 'steer' : 'queue');return true;@@ -2347,7 +2351,6 @@ export function ChatInput({if (showStopButtonRef.current &&- composerCanSubmitRef.current &&isComposerEnterTarget(event.target) &&event.key === 'Enter' &&(event.metaKey || event.ctrlKey) &&