Skip to content

Fix terminal-editor shift-drop firing on detached instances - #318756

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
vladstudio:fix/311164-terminal-editor-shift-drop
Sep 8, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
vladstudio:fix/311164-terminal-editor-shift-drop

Conversation

@vladstudio

@vladstudio Vlad Gerasimov (vladstudio) commented May 28, 2026

Copy link
Copy Markdown

Summary

Fixes #311164.

TerminalInstance._dndObserver (a MutableDisposable<IDisposable> holding the per-container DragAndDropObserver) was set by _initDragAndDrop but never cleared by detachFromElement. Because a TerminalEditor pane reuses its _overflowGuardElement across tab switches (setInput calls detachFromElement on the old instance and attachToElement on the new one against the same container), each newly attached terminal stacked another DragAndDropObserver on top of the leaked ones.

When the user shift-dropped a file onto the active editor-area terminal, the EditorDropTarget overlay correctly disposed itself in dragover, and the drop bubbled to the shared container, where every previously attached terminal's observer fired and called sendPath.

The fix clears the observer on detach and guards the deferred initializer so it cannot install an observer after the terminal has detached or moved to another container.

Test plan

  • Added regression coverage for detaching after the observer is initialized and reusing the container
  • Added regression coverage for detaching before deferred initialization runs
  • Full TerminalInstance unit test file passes (109 passing, 3 pending on the PR head)
  • Compile passes
  • ESLint passes for both changed files
  • Verified in Code OSS with two terminal editor tabs: a dropped path appears only in the active terminal

…t#311164)

`TerminalInstance._dndObserver` was set by `_initDragAndDrop` but never
cleared by `detachFromElement`. A `TerminalEditor` pane reuses its
`_overflowGuardElement` across tab switches, so when one terminal was
detached and another attached to the same container, the old instance's
DragAndDropObserver was still listening on it. A shift+drop then fired
`sendPath` on every previously-attached terminal in that pane.

Disposing the observer on detach removes the listeners from the prior
container.

Fixes microsoft#311164

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 28, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Prevents drag-and-drop listeners from leaking across terminal reattachments by clearing the DnD observer when a terminal detaches from its DOM container.

Changes:

  • Clear the terminal instance’s drag-and-drop observer during detachFromElement to avoid drop events being routed to the wrong instance after reattachment.

@vs-code-engineering

vs-code-engineering Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
  • src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

Suppressed comments (1)

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts:1059

  • clear() only disposes an observer that already exists. attachToElement defers _initDragAndDrop(container) with setTimeout, so a detach in the same turn clears nothing and the queued callback later installs an observer on the detached container, recreating the stale-listener bug. The deferred callback should also verify this._container === container (or be tracked and cancelled) before initializing.
		this._dndObserver.clear();
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add requested test

Ignore deferred drag-and-drop initialization when the terminal has already detached or moved to another container. Add coverage for both established and pending observers during terminal editor tab reuse.

Co-authored-by: Copilot <[email protected]>
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Vlad Gerasimov (@vladstudio) Please accept the terms.

@boedysutris-ctrl

boedysutris-ctrl commented Sep 6, 2026 via email

Copy link
Copy Markdown

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 4603a7f into microsoft:main Sep 8, 2026
32 of 33 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.138.0 milestone Sep 8, 2026
Alex Ross (alexr00) added a commit that referenced this pull request Sep 8, 2026
…335062)

Revert "Fix terminal-editor shift-drop firing on detached instances (#318756)"

This reverts commit 4603a7f.
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.

Dragging a file into one terminal editor while holding Shift inserts the path into other terminal editors as well

6 participants