Skip to content

[codex] fix(desktop): preserve chat cursor position#2993

Merged
Kitenite merged 1 commit into
mainfrom
fix-chat-gui-cursor-position-issue-on-rerender
Mar 29, 2026
Merged

[codex] fix(desktop): preserve chat cursor position#2993
Kitenite merged 1 commit into
mainfrom
fix-chat-gui-cursor-position-issue-on-rerender

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Mar 29, 2026

Summary

This change fixes the desktop chat composer moving the caret to the start of the prompt while typing.

What Changed

  • updated the chat prompt focus hook to depend on the stable textInput.focus callback instead of the full textInput controller object
  • kept the existing behavior of focusing the prompt when the pane becomes active, without re-focusing on ordinary input rerenders

Root Cause

useFocusPromptOnPane depended on the entire textInput object from the prompt controller. That object is recreated whenever the controlled prompt value changes, so the effect ran again on each keystroke while the pane was focused. Re-focusing the textarea during typing reset the selection and made the cursor jump.

Impact

Typing in the desktop chat composer should now preserve the caret position across rerenders, including edits in the middle of existing text.

Validation

  • cd apps/desktop && bun run typecheck

Summary by cubic

Fixes the desktop chat composer cursor jumping to the start while typing. The focus hook now uses the stable textInput.focus callback instead of the full controller, so the prompt keeps its caret on rerenders and only auto-focuses when the pane becomes active.

Written for commit c939232. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Improved chat input focus handling efficiency in the interface.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dac16e1a-5985-4e5b-ac7d-9170adf36d56

📥 Commits

Reviewing files that changed from the base of the PR and between 1ac52d4 and c939232.

📒 Files selected for processing (1)
  • apps/desktop/src/renderer/components/Chat/ChatInterface/hooks/useFocusPromptOnPane.ts

📝 Walkthrough

Walkthrough

A React hook was refactored to cache the textInput.focus method into a local variable before invoking it. The useEffect dependency array was updated to reference the cached focus function instead of the entire textInput object, changing from [isFocused, textInput] to [focusPrompt, isFocused].

Changes

Cohort / File(s) Summary
Focus Method Caching
apps/desktop/src/renderer/components/Chat/ChatInterface/hooks/useFocusPromptOnPane.ts
Extracted textInput.focus into a focusPrompt variable and updated the useEffect dependency array from [isFocused, textInput] to [focusPrompt, isFocused].

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit hopped through code so neat,
Cached the focus, made it sweet!
One small change, a methodly treat,
Dependencies now compete. 🐰✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-chat-gui-cursor-position-issue-on-rerender

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Kitenite Kitenite marked this pull request as ready for review March 29, 2026 19:09
@Kitenite Kitenite merged commit 8dc5c38 into main Mar 29, 2026
5 of 6 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant