Skip to content

Commit fd7ea2a

Browse files
committed
fix: preserve cursor position in question-answer mode
Only reset the composer when the active pending question changes. Previously the effect depended on the whole pending progress object, so editing the answer retriggered the effect and forced the cursor to the end on every keystroke. That broke left/right arrow movement and click-to-reposition in question-answer mode. Also keeps the earlier Alt+↑ / Alt+↓ keyboard navigation improvement. Fixes pingdotgg#528
1 parent 028fd42 commit fd7ea2a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,11 @@ export default function ChatView({ threadId }: ChatViewProps) {
946946
if (!activePendingProgress) {
947947
return;
948948
}
949+
// Only reset the composer when the active pending question changes.
950+
// If we key this effect on the whole progress object, every keystroke updates
951+
// `customAnswer`, retriggers the effect, and forces the cursor back to the end.
952+
// That breaks normal left/right arrow navigation and click-to-reposition while
953+
// answering a question.
949954
promptRef.current = activePendingProgress.customAnswer;
950955
setComposerCursor(activePendingProgress.customAnswer.length);
951956
setComposerTrigger(
@@ -958,7 +963,11 @@ export default function ChatView({ threadId }: ChatViewProps) {
958963
),
959964
);
960965
setComposerHighlightedItemId(null);
961-
}, [activePendingProgress, activePendingUserInput?.requestId]);
966+
}, [
967+
activePendingProgress?.activeQuestion?.id,
968+
activePendingQuestionIndex,
969+
activePendingUserInput?.requestId,
970+
]);
962971
useEffect(() => {
963972
attachmentPreviewHandoffByMessageIdRef.current = attachmentPreviewHandoffByMessageId;
964973
}, [attachmentPreviewHandoffByMessageId]);

0 commit comments

Comments
 (0)