Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set _lastFocusedWidget as undefined on widget blur #234610

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

oxcened
Copy link
Contributor

@oxcened oxcened commented Nov 25, 2024

Fixes #233761.

How to reproduce

  1. Have one open terminal (as default)
  2. Click on the button with the terminal name
  3. Click on "Change color..." and choose any color from the modal
  4. Click on the button with the terminal name
  5. Click on either "Rename...", "Split terminal", "Kill terminal"
  6. Expect the buttons to not work

Diagnosis

The problem happens when you pick a color in the modal mentioned above. As soon as you click a color, the modal briefly grabs focus before closing and applying your choice.

The issue boils down to this focus change. The QuickInputTree widget fires an onDidFocus event, which listService catches and uses to set _lastFocusedWidget.

But since the modal closes right away, _lastFocusedWidget ends up pointing to a list that’s no longer visible. Later, in terminalActions.ts, the getSelectedInstances function mistakenly thinks the colors from that list are selected terminals. So when terminalService.getInstanceFromIndex(selection) runs, it tries to use a color object as if it were a numeric index, causing the bug.

Solution

To fix this, I added a listener for the onDidBlur event on the widget. This works as the opposite of onDidFocus—it resets _lastFocusedWidget to undefined when the widget loses focus, like when you pick a color and the modal closes.

This makes sure that lists that aren’t actually focused don’t get treated as such by listService. With this change, getSelectedInstances now works as expected, solving the issue.

Before and after

Screen.Recording.2024-11-25.at.22.25.29.mov
Screen.Recording.2024-11-25.at.22.26.18.mov

Let me know if additional testing or adjustments are needed!

@oxcened oxcened force-pushed the fix-reset-last-focused-list-on-blur branch from d9cb6b5 to b0645ab Compare November 26, 2024 03:23
@meganrogge meganrogge added this to the January 2025 milestone Nov 26, 2024
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.

Unable to rename terminal when there is only 1 terminal (again)
2 participants