Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): keep composer focus restore intent across double capture
Shinkufad4257bff93
diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/useComposerSendFocusRestore.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/useComposerSendFocusRestore.test.tsxindex 777357a767..839d9cffc1 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/useComposerSendFocusRestore.test.tsx+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/useComposerSendFocusRestore.test.tsx@@ -104,6 +104,27 @@ describe('useComposerSendFocusRestore', () => {expect(editor.state.selection.to).toBe(6);});+ it('keeps the intent captured before the first lock when a later capture observes blurred state', () => {+ const editor = createEditor();+ const hook = renderRestoreHook(editor);++ focusComposerSelection(editor);+ act(() => {+ hook.result.current();+ });+ hook.rerender({ composerMutationLocked: true, sendDispatchInFlight: true });+ act(() => editor.view.dom.blur());+ // dispatchSend captures a second time after the lock stole focus; this must+ // not overwrite the intent captured while the composer was still focused.+ act(() => {+ hook.result.current();+ });+ hook.rerender({ composerMutationLocked: false, sendDispatchInFlight: false });+ flushAnimationFrames();++ expect(document.activeElement).toBe(editor.view.dom);+ });+it('keeps the restore intent until every composer lock is released', () => {const editor = createEditor();const hook = renderRestoreHook(editor);diff --git a/apps/desktop/src/renderer/components/new-chat/useComposerSendFocusRestore.ts b/apps/desktop/src/renderer/components/new-chat/useComposerSendFocusRestore.tsindex 283ab5f4d9..1f8135afa4 100644--- a/apps/desktop/src/renderer/components/new-chat/useComposerSendFocusRestore.ts+++ b/apps/desktop/src/renderer/components/new-chat/useComposerSendFocusRestore.ts@@ -104,6 +104,14 @@ export function useComposerSendFocusRestore(}, [composerMutationLocked, editor, sendDispatchInFlight]);return useCallback(() => {+ // dispatchSend 会在本地路径与远端路径各捕获一次焦点(第二处在 effort settle 后触发)。+ // 旧实现 restoreFocusAfterDispatchRef 用 || 合并防止互相覆盖;此捕获函数是直接赋值,+ // 本地路径第一处捕获后 setEditable(false) 已打掉焦点,第二处捕获时 editor.isFocused 为 false,+ // 会把第一处记住的 intent 覆盖成 null,解锁后不再恢复光标。+ // 因此同一 editor 已有待恢复 intent 时,后续捕获直接跳过。+ if (pendingRestoreRef.current && pendingRestoreRef.current.editor === editor) {+ return;+ }pendingRestoreRef.current =editor && !editor.isDestroyed && editor.isFocused? { editor, focusAnchor: editor.view.dom.ownerDocument.activeElement }