Skip to content

Conversation

@senyai
Copy link

@senyai senyai commented Dec 9, 2024

Drag and dropping multiple files into the terminal has never worked; only one path was inserted. This pull request fixes the issue. This request is very important to me because I like to git stash selected files. I want to be able to write git stash -- and drop selected files from the SCM view.

Please forgive me for not referencing an issue number here.

@senyai
Copy link
Author

senyai commented Dec 9, 2024

@microsoft-github-policy-service agree

@senyai
Copy link
Author

senyai commented Dec 23, 2024

@Tyriar hi! what do you think about this pull request? Should I just wait for it to be reviewed?

@senyai senyai force-pushed the senyai-insert-paths branch from 483464c to 9fcb8b7 Compare November 13, 2025 07:48
@Tyriar
Copy link
Member

Tyriar commented Nov 13, 2025

Is there an issue that this fixes? Normally changes need to be discussed in an issue, it's not certain we would accept such a change and the issue is required to verify the issue before it reaches stable anyway.

@senyai
Copy link
Author

senyai commented Nov 23, 2025

@Tyriar you are right, sorry for not following the protocol. I created the issue #279026.

I tested this code before, but I currently have issues setting up environment for compiling VS Code, so latest code is not tested.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for dragging and dropping multiple files into the terminal, where previously only a single file path would be inserted. The implementation updates the drag-and-drop handlers to collect all dropped files and join their paths with spaces when sending to the terminal.

Key Changes

  • Refactored drag-and-drop event handlers to collect and process arrays of file URIs instead of single files
  • Introduced sendPaths() method to handle multiple file paths, joining them with spaces
  • Renamed sendPath() to executePath() to clarify its purpose (sends path with execution)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/vs/workbench/contrib/terminal/browser/terminalTabsList.ts Updated _handleExternalDrop to collect multiple file URIs from drag events and call sendPaths()
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Added sendPaths() method, renamed sendPath() to executePath(), updated drag-and-drop controller to emit URI[] arrays
src/vs/workbench/contrib/terminal/browser/terminalActions.ts Updated call from sendPath() to executePath() for running active file
src/vs/workbench/contrib/terminal/browser/terminal.ts Updated interface definitions with new executePath() and sendPaths() method signatures

if (resource) {
resources.push(URI.file(resource));
}

Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

[nitpick] There's an extra blank line here that should be removed to maintain consistent code formatting.

Suggested change

Copilot uses AI. Check for mistakes.
executePath(originalPath: URI): Promise<void>;

/**
* Sends a paths to the terminal instance, preparing it as needed based on the detected shell
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Typo in documentation: "Sends a paths" should be "Sends paths" (remove the article "a").

Suggested change
* Sends a paths to the terminal instance, preparing it as needed based on the detected shell
* Sends paths to the terminal instance, preparing it as needed based on the detected shell

Copilot uses AI. Check for mistakes.
* The character(s) added are \n or \r\n, depending on the platform. This defaults to `true`.
*/
sendPath(originalPath: string | URI, shouldExecute: boolean): Promise<void>;
executePath(originalPath: URI): Promise<void>;
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The interface signature for executePath specifies originalPath: URI, but the implementation in terminalInstance.ts:1350 accepts originalPath: string | URI. This inconsistency could lead to type errors. The interface should match the implementation by accepting string | URI instead of just URI.

Suggested change
executePath(originalPath: URI): Promise<void>;
executePath(originalPath: string | URI): Promise<void>;

Copilot uses AI. Check for mistakes.
*
* @param originalPaths The paths to send.
*/
sendPaths(originalPaths: URI[]): Promise<void>;
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The interface signature for sendPaths specifies originalPaths: URI[], but the implementation in terminalInstance.ts:1354 accepts originalPaths: (string | URI)[]. This inconsistency could lead to type errors. The interface should match the implementation by accepting (string | URI)[] instead of just URI[].

Suggested change
sendPaths(originalPaths: URI[]): Promise<void>;
sendPaths(originalPaths: (string | URI)[]): Promise<void>;

Copilot uses AI. Check for mistakes.
}

if (!resource) {
if (!resources) {
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The check if (!resources) will not catch the case where resources is an empty array. After the filesystem file loop (lines 782-788), resources could be an empty array [], which would pass this check but fail when calling instance.sendPaths(resources) with an empty array. Consider changing this to if (!resources || resources.length === 0) to properly handle the empty array case.

Suggested change
if (!resources) {
if (!resources || resources.length === 0) {

Copilot uses AI. Check for mistakes.
Comment on lines +1354 to 1357
async sendPaths(originalPaths: (string | URI)[]): Promise<void> {
const paths = await Promise.all(originalPaths.map((path) => this.preparePathForShell(path)));
return this.sendText(paths.join(' '), false);
}
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The new sendPaths method lacks test coverage. Since terminalInstance.test.ts has comprehensive tests for other TerminalInstance methods, consider adding tests to verify that sendPaths correctly joins multiple paths with spaces and calls sendText with the expected parameters. This would ensure the multi-file drag-and-drop feature works correctly.

Copilot uses AI. Check for mistakes.
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.

2 participants