Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Browser issue (#12946)
Browse files Browse the repository at this point in the history
* Browser issue fix

These two sections check for Urls being dragged in to the browser.

* There was a bug in the unit test

So for some reason this changed which I did not perform showed up in my
master it seemed that one did not have access and the new one did. In
the health status test under extension tests, the connection would
timeout.

* JSLint syntax fix

JSLint want’s this instead of “==“. I had actually done a check with an
online checker and I forgot to make the change.

* Revert "There was a bug in the unit test"

This reverts commit 887e3d5.

* Simplify URI-list antipropagation

These are the changes as requested by @petetnt. The behavior was packed
into a function. Generally `types` is not null but was protected on the
case it is. Files must be null or the length must be 0 now.

* Indentation and spacing

Fixed extra indentation and spacing issues

* Clean comments

Cleaned up the comments, some were redundant to the functions
description. I gave the different cases of `types` values when files
and text is dragged/dropped into Brackets.
  • Loading branch information
jamran7 authored and petetnt committed Dec 6, 2016
1 parent 560bd20 commit 973cf51
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/utils/DragAndDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ define(function (require, exports, module) {
// No valid entries found
return false;
}

/**
* Determines if the event contains a type list that has a URI-list.
* If it does and contains an empty file list, then what is being dropped is a URL.
* If that is true then we stop the event propagation and default behavior to save Brackets editor from the browser taking over.
* @param {Array.<File>} files Array of File objects from the event datastructure. URLs are the only drop item that would contain a URI-list.
* @param {event} event The event datastucture containing datatransfer information about the drag/drop event. Contains a type list which may or may not hold a URI-list depending on what was dragged/dropped. Interested if it does.
*/
function stopURIListPropagation(files, event) {
var types = event.dataTransfer.types;

if ((!files || !files.length) && types) { // We only want to check if a string of text was dragged into the editor
types.forEach(function (value) {
//Draging text externally (dragging text from another file): types has "text/plain" and "text/html"
//Draging text internally (dragging text to another line): types has just "text/plain"
//Draging a file: types has "Files"
//Draging a url: types has "text/plain" and "text/uri-list" <-what we are interested in
if (value === "text/uri-list") {
event.stopPropagation();
event.preventDefault();
return;
}
});
}
}

/**
* Open dropped files
Expand Down Expand Up @@ -156,6 +181,9 @@ define(function (require, exports, module) {
event = event.originalEvent || event;

var files = event.dataTransfer.files;

stopURIListPropagation(files, event);

if (files && files.length) {
event.stopPropagation();
event.preventDefault();
Expand All @@ -174,6 +202,9 @@ define(function (require, exports, module) {
event = event.originalEvent || event;

var files = event.dataTransfer.files;

stopURIListPropagation(files, event);

if (files && files.length) {
event.stopPropagation();
event.preventDefault();
Expand Down

0 comments on commit 973cf51

Please sign in to comment.