diff --git a/packages/core/src/browser/shell/application-shell.ts b/packages/core/src/browser/shell/application-shell.ts index 7336a6fd2ea93..f265b89593c78 100644 --- a/packages/core/src/browser/shell/application-shell.ts +++ b/packages/core/src/browser/shell/application-shell.ts @@ -22,7 +22,7 @@ import { } from '@phosphor/widgets'; import { Message } from '@phosphor/messaging'; import { IDragEvent } from '@phosphor/dragdrop'; -import { RecursivePartial, Event as CommonEvent, DisposableCollection, Disposable, environment, isObject } from '../../common'; +import { RecursivePartial, Event as CommonEvent, DisposableCollection, Disposable, environment, isObject, UntitledResourceResolver, UNTITLED_SCHEME } from '../../common'; import { animationFrame } from '../browser'; import { Saveable, SaveableWidget, SaveOptions } from '../saveable'; import { StatusBarImpl, StatusBarEntry, StatusBarAlignment } from '../status-bar/status-bar'; @@ -232,6 +232,9 @@ export class ApplicationShell extends Widget { @inject(OpenerService) protected readonly openerService: OpenerService; + @inject(UntitledResourceResolver) + protected readonly untitledResourceResolver: UntitledResourceResolver; + protected readonly onDidAddWidgetEmitter = new Emitter(); readonly onDidAddWidget = this.onDidAddWidgetEmitter.event; protected fireDidAddWidget(widget: Widget): void { @@ -572,10 +575,21 @@ export class ApplicationShell extends Widget { uris.forEach(openUri); } else if (event.dataTransfer.files?.length > 0) { // the files were dragged from the outside the workspace - Array.from(event.dataTransfer.files).forEach(file => { - if (file.path) { - const fileUri = URI.fromFilePath(file.path); - openUri(fileUri); + Array.from(event.dataTransfer.files).forEach(async file => { + if (environment.electron.is()) { + if (file.path) { + const fileUri = URI.fromFilePath(file.path); + openUri(fileUri); + } + } else { + const fileContent = await file.text(); + const fileName = file.name; + const untitledResource = await this.untitledResourceResolver.createUntitledResource( + fileContent, + undefined, + new URI(`${UNTITLED_SCHEME}:/${fileName}`) + ); + openUri(untitledResource.uri); } }); }