Browse Source

Merge pull request #90 from blink1073/drag-bug

Fix drag and drop logic in file browser
A. Darian 8 years ago
parent
commit
2fd1e4f0a1
2 changed files with 16 additions and 21 deletions
  1. 7 9
      src/filebrowser/crumbs.ts
  2. 9 12
      src/filebrowser/listing.ts

+ 7 - 9
src/filebrowser/crumbs.ts

@@ -219,18 +219,16 @@ class BreadCrumbs extends Widget {
 
     // Get the path based on the target node.
     let index = this._crumbs.indexOf(target);
-    if (index === -1) return;
-    var path = BREAD_CRUMB_PATHS[index];
+    if (index === -1) {
+      return;
+    }
+    let path = BREAD_CRUMB_PATHS[index];
 
     // Move all of the items.
     let promises: Promise<void>[] = [];
-    let items = this._model.sortedItems;
-    for (let item of items) {
-      var name = item.name;
-      if (!this._model.isSelected(name)) {
-        continue;
-      }
-      var newPath = path + name;
+    let names = event.mimeData.getData(utils.CONTENTS_MIME) as string[];
+    for (let name of names) {
+      let newPath = path + name;
       promises.push(this._model.rename(name, newPath).catch(error => {
         if (error.xhr) {
           error.message = `${error.xhr.status}: error.statusText`;

+ 9 - 12
src/filebrowser/listing.ts

@@ -893,11 +893,12 @@ class DirListing extends Widget {
       if (index === -1) {
         return;
       }
+      let item = this._model.sortedItems[index];
       let target = this._items[index];
       if (!target.classList.contains(FOLDER_TYPE_CLASS)) {
         return;
       }
-      if (target.classList.contains(SELECTED_CLASS)) {
+      if (!this._softSelection && this._model.isSelected(item.name)) {
         return;
       }
       target.classList.add(utils.DROP_TARGET_CLASS);
@@ -935,6 +936,7 @@ class DirListing extends Widget {
   private _evtDrop(event: IDragEvent): void {
     event.preventDefault();
     event.stopPropagation();
+    clearTimeout(this._selectTimer);
     if (event.proposedAction === DropAction.None) {
       event.dropAction = DropAction.None;
       return;
@@ -956,19 +958,13 @@ class DirListing extends Widget {
     // Get the path based on the target node.
     let index = this._items.indexOf(target);
     let items = this._model.sortedItems;
-    var path = items[index].name + '/';
+    let path = items[index].name + '/';
 
     // Move all of the items.
     let promises: Promise<IContentsModel>[] = [];
-    for (let item of items) {
-      if (!this._softSelection && !this._model.isSelected(item.name)) {
-        continue;
-      }
-      if (this._softSelection !== item.name) {
-        continue;
-      }
-      var name = item.name;
-      var newPath = path + name;
+    let names = event.mimeData.getData(utils.CONTENTS_MIME) as string[];
+    for (let name of names) {
+      let newPath = path + name;
       promises.push(this._model.rename(name, newPath).catch(error => {
         if (error.xhr) {
           error.message = `${error.xhr.statusText} ${error.xhr.status}`;
@@ -1029,7 +1025,7 @@ class DirListing extends Widget {
       supportedActions: DropActions.Move,
       proposedAction: DropAction.Move
     });
-    this._drag.mimeData.setData(utils.CONTENTS_MIME, null);
+    this._drag.mimeData.setData(utils.CONTENTS_MIME, selectedNames);
     if (item && item.type !== 'directory') {
       this._drag.mimeData.setData(FACTORY_MIME, () => {
         this._registry.open(item.path);
@@ -1040,6 +1036,7 @@ class DirListing extends Widget {
     this._drag.start(clientX, clientY).then(action => {
       console.log('action', action);
       this._drag = null;
+      clearTimeout(this._selectTimer);
     });
     document.removeEventListener('mousemove', this, true);
   }