Skip to content

Conversation

@oxcened
Copy link
Contributor

@oxcened oxcened commented Nov 25, 2024

Fixes #234791.

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
Copy link
Contributor

@meganrogge meganrogge left a comment

Choose a reason for hiding this comment

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

Thanks!

@meganrogge meganrogge enabled auto-merge (squash) December 8, 2024 15:19
@meganrogge
Copy link
Contributor

cc @Tyriar

@meganrogge meganrogge merged commit acc7cf2 into microsoft:main Dec 8, 2024
6 checks passed
amunger added a commit that referenced this pull request Jan 22, 2025
amunger added a commit that referenced this pull request Jan 22, 2025
* fix editable check

* Revert "fix: set _lastFocusedWidget as undefined on widget blur (#234610)"

This reverts commit acc7cf2.
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jan 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

menu options stop working after terminal's color is changed

3 participants