Skip to content

Commit

Permalink
Prevent default dnd behavior
Browse files Browse the repository at this point in the history
Fixes eclipse-theia#674

- prevent default dnd (drag & drop) behavior when dragging a file from
the filesystem into Theia. The default browser behavior meant that
the application was replaced by the browser attempting to open the file
as a URL.
- [minor] fix a few typos in the same file.

Signed-off-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto authored and akosyakov committed Feb 24, 2020
1 parent ed55e06 commit 82b4a00
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/core/src/browser/frontend-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface FrontendApplicationContribution {
initializeLayout?(app: FrontendApplication): MaybePromise<void>;

/**
* An event is emmited when a layout is initialized, but before the shell is attached.
* An event is emitted when a layout is initialized, but before the shell is attached.
*/
onDidInitializeLayout?(app: FrontendApplication): MaybePromise<void>;
}
Expand Down Expand Up @@ -173,6 +173,14 @@ export class FrontendApplication {
if (isOSX) {
document.body.addEventListener('wheel', preventNavigation, { passive: false });
}
// Prevent the default browser behavior when dragging and dropping files into the window.
window.addEventListener('dragover', event => {
event.preventDefault();
}, false);
window.addEventListener('drop', event => {
event.preventDefault();
}, false);

}

/**
Expand Down Expand Up @@ -231,7 +239,7 @@ export class FrontendApplication {
} catch (error) {
if (ApplicationShellLayoutMigrationError.is(error)) {
console.warn(error.message);
console.info('Initializing the defaut layout instead...');
console.info('Initializing the default layout instead...');
} else {
console.error('Could not restore layout', error);
}
Expand Down

0 comments on commit 82b4a00

Please sign in to comment.