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(mobile): 切换任务时作废语音结束的隐藏光标标记

Dashc7a3326af98f
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index c127274de0..b1e4c96a8c 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -1436,6 +1436,8 @@ function SessionScreenContent({ beforeSessionSwitchRef, newSessionActionRef }: S
// 听写期间原生光标停在插入前的位置;停止后要等最终识别与润色完成才定位到插入末尾。
// 这段时间继续隐藏光标,避免先在文字中间闪现再跳到末尾。
const [voiceCaretPlacementPending, setVoiceCaretPlacementPending] = useState(false);
+ // 隐藏光标属于发起停止的那个任务:切任务时作废,迟到的停止收尾不得改动新任务的标记。
+ const voiceCaretPlacementSeqRef = useRef(0);
// 「语音结束保持展开」hold:语音真实收尾(busy → done/error)时布防,草稿仍有
// 内容即生效、一行文字也不收(composerVoiceHoldActive);下拉收起 / 失焦 / 草稿清空解除。
const [composerVoiceHoldArmed, setComposerVoiceHoldArmed] = useState(false);
@@ -5835,6 +5837,8 @@ function SessionScreenContent({ beforeSessionSwitchRef, newSessionActionRef }: S
// 不依赖旧 controller 的迟到 done 回调来复位新页面。
setVoiceState('idle');
setComposerVoiceHoldArmed(false);
+ voiceCaretPlacementSeqRef.current += 1;
+ setVoiceCaretPlacementPending(false);
if (controller) void controller.cancel().catch(() => undefined);
discardPendingPrewarm();
};
@@ -5853,6 +5857,7 @@ function SessionScreenContent({ beforeSessionSwitchRef, newSessionActionRef }: S
voiceSuppressNextPressRef.current = false;
voiceRecordingActiveRef.current = false;
setVoiceReleaseToSendActive(false);
+ const caretPlacementSeq = ++voiceCaretPlacementSeqRef.current;
setVoiceCaretPlacementPending(true);
setVoiceState('submitting');
setVoiceError(null);
@@ -5876,7 +5881,7 @@ function SessionScreenContent({ beforeSessionSwitchRef, newSessionActionRef }: S
if (options.focusInput) inputBeforeStop.applyDocumentAndFocusSelection(composerDocumentRef.current, insertionEnd);
else inputBeforeStop.applyDocumentAndSetSelection(composerDocumentRef.current, insertionEnd);
}
- setVoiceCaretPlacementPending(false);
+ if (voiceCaretPlacementSeqRef.current === caretPlacementSeq) setVoiceCaretPlacementPending(false);
});
if (options.sendAfterTranscribe && (composerDocumentHasContent(latestDocument) || attachments.length > 0)) {
const sendLatest = sendLatestRef.current;
@@ -5886,7 +5891,7 @@ function SessionScreenContent({ beforeSessionSwitchRef, newSessionActionRef }: S
} catch (err) {
voiceControllerSessionRef.current = null;
voiceRecordingActiveRef.current = false;
- setVoiceCaretPlacementPending(false);
+ if (voiceCaretPlacementSeqRef.current === caretPlacementSeq) setVoiceCaretPlacementPending(false);
setVoiceState('error');
setVoiceError(formatRemoteError(err));
} finally {