@devries-cameron20 / t3code-1 / commits / f63cda22fa
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix: improve business logic in prompt editor and fix cursor bugs in Plan mode (#867)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Noah Gregory committed Mar 12, 2026 at 14:24 UTC f63cda22fa6e9b98de1caec057960dce28248d37
2 files changed +50 -20
apps/web/src/components/ChatView.tsx
+32 -9
@@ -633,23 +633,46 @@ export default function ChatView({ threadId }: ChatViewProps) {
633 pendingUserInputs.length > 0 ||
634 (showPlanFollowUpPrompt && activeProposedPlan !== null);
635 const composerFooterHasWideActions = showPlanFollowUpPrompt || activePendingProgress !== null;
636 + const lastSyncedPendingInputRef = useRef<{
637 + requestId: string | null;
638 + questionId: string | null;
639 + } | null>(null);
640 useEffect(() => {
637 - if (!activePendingProgress) {
641 + const nextCustomAnswer = activePendingProgress?.customAnswer;
642 + if (typeof nextCustomAnswer !== "string") {
643 + lastSyncedPendingInputRef.current = null;
644 return;
645 }
640 - promptRef.current = activePendingProgress.customAnswer;
641 - setComposerCursor(activePendingProgress.customAnswer.length);
646 + const nextRequestId = activePendingUserInput?.requestId ?? null;
647 + const nextQuestionId = activePendingProgress?.activeQuestion?.id ?? null;
648 + const questionChanged =
649 + lastSyncedPendingInputRef.current?.requestId !== nextRequestId ||
650 + lastSyncedPendingInputRef.current?.questionId !== nextQuestionId;
651 + const textChangedExternally = promptRef.current !== nextCustomAnswer;
652 +
653 + lastSyncedPendingInputRef.current = {
654 + requestId: nextRequestId,
655 + questionId: nextQuestionId,
656 + };
657 +
658 + if (!questionChanged && !textChangedExternally) {
659 + return;
660 + }
661 +
662 + promptRef.current = nextCustomAnswer;
663 + setComposerCursor(nextCustomAnswer.length);
664 setComposerTrigger(
665 detectComposerTrigger(
644 - activePendingProgress.customAnswer,
645 - expandCollapsedComposerCursor(
646 - activePendingProgress.customAnswer,
647 - activePendingProgress.customAnswer.length,
648 - ),
666 + nextCustomAnswer,
667 + expandCollapsedComposerCursor(nextCustomAnswer, nextCustomAnswer.length),
668 ),
669 );
670 setComposerHighlightedItemId(null);
652 - }, [activePendingProgress, activePendingUserInput?.requestId]);
671 + }, [
672 + activePendingProgress?.customAnswer,
673 + activePendingUserInput?.requestId,
674 + activePendingProgress?.activeQuestion?.id,
675 + ]);
676 useEffect(() => {
677 attachmentPreviewHandoffByMessageIdRef.current = attachmentPreviewHandoffByMessageId;
678 }, [attachmentPreviewHandoffByMessageId]);
apps/web/src/components/ComposerPromptEditor.tsx
+18 -11
@@ -629,6 +629,7 @@ function ComposerPromptEditorInner({
629 const [editor] = useLexicalComposerContext();
630 const onChangeRef = useRef(onChange);
631 const snapshotRef = useRef({ value, cursor: clampCursor(value, cursor) });
632 + const isApplyingControlledUpdateRef = useRef(false);
633
634 useEffect(() => {
635 onChangeRef.current = onChange;
@@ -645,21 +646,26 @@ function ComposerPromptEditorInner({
646 return;
647 }
648
648 - if (previousSnapshot.value !== value) {
649 - editor.update(() => {
650 - $setComposerEditorPrompt(value);
651 - });
652 - }
653 -
649 snapshotRef.current = { value, cursor: normalizedCursor };
650
651 const rootElement = editor.getRootElement();
657 - if (!rootElement || document.activeElement !== rootElement) {
652 + const isFocused = Boolean(rootElement && document.activeElement === rootElement);
653 + if (previousSnapshot.value === value && !isFocused) {
654 return;
655 }
656
657 + isApplyingControlledUpdateRef.current = true;
658 editor.update(() => {
662 - $setSelectionAtComposerOffset(normalizedCursor);
659 + const valueChanged = previousSnapshot.value !== value;
660 + if (previousSnapshot.value !== value) {
661 + $setComposerEditorPrompt(value);
662 + }
663 + if (valueChanged || isFocused) {
664 + $setSelectionAtComposerOffset(normalizedCursor);
665 + }
666 + });
667 + queueMicrotask(() => {
668 + isApplyingControlledUpdateRef.current = false;
669 });
670 }, [cursor, editor, value]);
671
@@ -705,9 +711,7 @@ function ComposerPromptEditorInner({
711 focus: () => {
712 focusAt(snapshotRef.current.cursor);
713 },
708 - focusAt: (nextCursor: number) => {
709 - focusAt(nextCursor);
710 - },
714 + focusAt,
715 focusAtEnd: () => {
716 focusAt(snapshotRef.current.value.length);
717 },
@@ -728,6 +732,9 @@ function ComposerPromptEditorInner({
732 if (previousSnapshot.value === nextValue && previousSnapshot.cursor === nextCursor) {
733 return;
734 }
735 + if (isApplyingControlledUpdateRef.current) {
736 + return;
737 + }
738 snapshotRef.current = {
739 value: nextValue,
740 cursor: nextCursor,