Skip to content

Conversation

@xyOz-dev
Copy link
Contributor

@xyOz-dev xyOz-dev commented May 28, 2025

Related GitHub Issue

Closes: #2189

Description

Fixes the related issue

Test Procedure

  1. Open Roo
  2. Type in the Input Area
  3. Tab Out
  4. Tab Back in
  5. Type Something again

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.

Side note its the first time an upstream change has come up in my commits, not sure if it should be removed or not but it was required to merge into current branch at time of PR Creation


Important

Fixes chat focus issues by adding timeout-based focus handling in ClineProvider and ChatView.tsx.

  • Behavior:
    • Adds focus handling with timeout in ClineProvider to ensure input focus when window regains focus.
    • Updates ChatView.tsx to handle focusInput action with a timeout to ensure input focus.
  • Tests:
    • Adds tests in ClineProvider.test.ts to verify focus handling when window state changes.
    • Ensures focusInput action is tested for visibility and focus conditions.
  • Misc:
    • Introduces focusTimeoutId in ClineProvider and focusTimeoutRef in ChatView.tsx to manage focus timing.

This description was created by Ellipsis for fc12099. You can customize this summary. It will automatically update as commits are pushed.

@xyOz-dev xyOz-dev requested review from cte and mrubens as code owners May 28, 2025 10:42
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels May 28, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label May 28, 2025
@hannesrudolph hannesrudolph moved this from Triage to Issue [In Progress] in Roo Code Roadmap May 28, 2025
@hannesrudolph hannesrudolph moved this from Issue [In Progress] to PR [Needs Preliminary Review] in Roo Code Roadmap May 28, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels May 28, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Thanks @xyOz-dev,
This looks like a good idea, I just left a couple of small points to improve the timeout logic.

if (this.view?.visible) {
this.postMessageToWebview({ type: "action", action: "focusInput" })
}
this.focusTimeoutId = undefined
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit concerned about potential race conditions here. You're using a 100ms timeout in the provider while ChatView uses 50ms. If someone rapidly switches between windows, multiple focus events could queue up and cause unexpected behavior.

Maybe we could use the same timeout duration in both places? Or even better, implement a proper debounce mechanism to handle rapid focus changes more gracefully.

await this.removeClineFromStack()
this.log("Cleared task")

if (this.focusTimeoutId) {
Copy link
Member

Choose a reason for hiding this comment

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

Good that you're clearing the timeout in dispose(), but what happens if the view gets disposed while a timeout is still pending? The timeout would still fire and try to access this.view which might be disposed.

It might be a good idea to add a check in the timeout callback to ensure the view still exists and hasn't been disposed before trying to post a message to it.

clearTimeout(focusTimeoutRef.current)
}

focusTimeoutRef.current = setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Since there's timeout logic here as well similar to what's on ClineProvider. Have you considered extracting this into a shared utility function or hook? Something like useDebouncedFocus() could handle the timeout.

await provider.resolveWebviewView(mockWebviewView)

mockPostMessage.mockClear()

Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to swap out those arbitrary timeouts like 150ms and 10ms for Jest's timer mocks, like jest.useFakeTimers() and jest.runAllTimers()? Should make the test faster.

Also, we could test for rapid focus changes to ensure the debouncing is holding up well.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap May 28, 2025
@daniel-lxs daniel-lxs marked this pull request as draft May 28, 2025 22:58
SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request Jun 13, 2025
* migrate apiConfiguration

* fix type issue

---------

Co-authored-by: Elephant Lumps <[email protected]>
@hannesrudolph
Copy link
Collaborator

stale

@github-project-automation github-project-automation bot moved this from PR [Draft / In Progress] to Done in Roo Code Roadmap Jul 7, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Draft / In Progress size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Focus Lost in Chat Text Box After Alt+Tab

3 participants