提交 9db49eeb 编写于 作者: J Joao Portela

Inserting file path on the terminal, when dragging a file to it

上级 491f1ba3
...@@ -204,6 +204,28 @@ export class TerminalPanel extends Panel { ...@@ -204,6 +204,28 @@ export class TerminalPanel extends Panel {
event.stopPropagation(); event.stopPropagation();
} }
})); }));
this._register(DOM.addDisposableListener(this._parentDomElement, DOM.EventType.DROP, (e: DragEvent) => {
if (e.target === this._parentDomElement || DOM.isAncestor(e.target as HTMLElement, this._parentDomElement)) {
if (!e.dataTransfer) {
return;
}
const url = e.dataTransfer.getData('URL');
const filePath = this._getPathFromUrl(url);
const terminal = this._terminalService.getActiveInstance();
// for files dragged from the tree explorer
if (filePath) {
terminal.sendText(filePath, false);
return;
}
// for files dragged from the filesystem
const files = e.dataTransfer.files;
if (files.length > 0) {
terminal.sendText(files[0].path, false);
}
}
}));
} }
private _refreshCtrlHeld(e: KeyboardEvent): void { private _refreshCtrlHeld(e: KeyboardEvent): void {
...@@ -255,4 +277,17 @@ export class TerminalPanel extends Panel { ...@@ -255,4 +277,17 @@ export class TerminalPanel extends Panel {
a.fontSize !== b.fontSize || a.fontSize !== b.fontSize ||
a.lineHeight !== b.lineHeight; a.lineHeight !== b.lineHeight;
} }
/**
* Removes the trailing file:// from a URL if it exists
* Returns null if it doesn't
*/
private _getPathFromUrl(url: string): string {
const fileRefex = /^file:\/\/(.+)/;
const result = fileRefex.exec(url);
if (result && result.length === 2) {
return result[1];
}
return null;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册