Skip to content

fix FocusActiveChat support in tabs#84

Open
deeptoaster wants to merge 1 commit intoDanBradbury:mainfrom
deeptoaster:patch-1
Open

fix FocusActiveChat support in tabs#84
deeptoaster wants to merge 1 commit intoDanBradbury:mainfrom
deeptoaster:patch-1

Conversation

@deeptoaster
Copy link

FocusActiveChat is currently broken when a user tries to call it from a tab other than the one the active Copilot Chat window is in.

This is because window IDs are global (with respect to tabs), while window numbers are local. The existing code would attempt to search for the Copilot Chat window by ID (globally), convert it to a window number (local, losing tab information), convert it back to ID (global, now possibly on the wrong tab), and switch to it. If the Copilot Chat window is on a different tab, this means that you end up either

  • switching to an unrelated window that happens to share the same number on the current tab, or
  • throw an error, if there's no window by that number on the current tab.

Fundamentally, this is because this function entirely ignores the concept of tabs. We can resolve this in one of two ways:

  1. If the Copilot Chat window is open but it's on a different tab, switch to that tab and focus the Copilot Chat window.
  2. Ignore Copilot Chat windows on other tabs. Only focus a Copilot Chat window if it exists on the current tab, and open a new one otherwise.

Option 2 feels more intuitive, so I went for that.

This PR also removes an unnecessary loop through all the windows in the user's entire Vim session. win_findbuf() (for option 1) or bufwinnr() (for option 2) gets you the same information much more efficiently.

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