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

Issue #199927: Fix terminal tab list drag/drop selection #211482

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/vs/workbench/contrib/terminal/browser/terminalTabsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ class TerminalTabsDragAndDrop extends Disposable implements IListDragAndDrop<ITe
constructor(
@ITerminalService private readonly _terminalService: ITerminalService,
@ITerminalGroupService private readonly _terminalGroupService: ITerminalGroupService,
@IListService private readonly _listService: IListService,
) {
super();
this._primaryBackend = this._terminalService.getPrimaryBackend();
Expand Down Expand Up @@ -707,10 +708,27 @@ class TerminalTabsDragAndDrop extends Disposable implements IListDragAndDrop<ITe
}

let focused = false;
// Retrieve the currently active instance asynchronously
let activeInstancePromise = this._terminalService.activeInstance;
Copy link
Member

Choose a reason for hiding this comment

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

There's a bunch of lint warnings about using const instead of let

let setActiveInstance = async (instance: ITerminalInstance) => {
const activeInstance = await activeInstancePromise; // Ensure the promise is resolved before comparison.
Comment on lines +711 to +714
Copy link
Member

Choose a reason for hiding this comment

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

this._terminalService.activeInstance is syunc, so this await doesn't seem to do anything.

if (activeInstance === instance) {
this._terminalService.setActiveInstance(instance);
}
};

for (const instance of sourceInstances) {
let targetWasFocus = (targetInstance === this._terminalService.activeInstance);
this._terminalGroupService.moveGroup(instance, targetInstance);
if (!focused) {
this._terminalService.setActiveInstance(instance);
// Await the setActiveInstance call to keep the loop synchronous
await setActiveInstance(instance);
if (targetWasFocus) {
if (targetIndex)
this._listService.lastFocusedList?.setSelection([targetIndex]);
else
this._listService.lastFocusedList?.setSelection([0]);
}
Comment on lines +726 to +731
Copy link
Member

Choose a reason for hiding this comment

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

This fixes the problem when dragging the second, inactive tab to the top. But not when dragging the first, inactive tab to the bottom.

focused = true;
}
}
Expand Down