Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Allow reordering project folders via drag and drop - #525

Merged
BinaryMuse merged 29 commits into
atom:masterfrom
forivall:drag-and-drop-root
Oct 26, 2016
Merged

BinaryMuse merged 29 commits into
atom:masterfrom
forivall:drag-and-drop-root

Conversation

@forivall

@forivall forivall commented Jul 18, 2015 •

Copy link
Copy Markdown
Contributor

Fixes #691

This uses the same logic that moving tabs uses to reposition project folders within the tree view.

move-project-folders

  • implement
  • update to interoperate with file movement dragging
  • fix placeholder width
  • add tests

Future additions:

  • reduce amount of duplicated code - needs coordination with tabs-view and drag-and-drop file moving
  • allow dragging in folders from the filesystem - needs electron support first, unfortunately. Or it's just broken in kwin.

Bugfixes

@alex88

alex88 commented Sep 4, 2015

Copy link
Copy Markdown

+1 this would be great, specially with a lot of folders not alphabetically ordered

@forivall

forivall commented Sep 4, 2015

Copy link
Copy Markdown
Contributor Author

I've updated this to work with the drag and drop changes in master. The semantics are that project folder dragging will occur if the drop occurs over the top half of a project folder entry, or over a file entry. The placeholder will appear if and only if project folder movement will occur, otherwise, selection will appear.

Alternate semantics that I've thought about are that file movement should only occur if the user is holding down the shift key, similar to many file managers.

forivall referenced this pull request in danielbrodin/atom-project-manager Sep 20, 2015
@brunogaspar

Copy link
Copy Markdown

+1

Comment thread lib/helpers.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's from this PR: #565 ; I accidentally merged it in at some point. I can rebase it out if needed.

@winstliu

Copy link
Copy Markdown
Contributor

Can you please rebase on top of master so that only the changes specific to this PR get displayed in the diff? It gets confusing reviewing when there's changes from other, unrelated PRs.

@forivall

Copy link
Copy Markdown
Contributor Author

@50Wliu Rebased. The other PR isn't 100% unrelated, but the fix is disjoint. 😉

@marjakm

marjakm commented Jan 22, 2016

Copy link
Copy Markdown

+1

@forivall

forivall commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

Rebased and updated. Tests all work.

@50Wliu ping!

@winstliu

winstliu commented Feb 3, 2016

Copy link
Copy Markdown
Contributor

/cc @atom/feedback

@mxstbr

mxstbr commented Apr 14, 2016

Copy link
Copy Markdown

Is there a particular reason this wasn't merged yet? I'd love to have this feature.

@krzysztof-sikorski

Copy link
Copy Markdown

Please make this behavior optional (toggled by a setting). Too many times I had accidentally dragged an entry instead of clicking on it.

@moritzreiter

Copy link
Copy Markdown

@mxstbr I guess someone with the proper authorization needs to review and approve the code (there's a "needs-review" label attached).

@thedaniel

thedaniel commented May 2, 2016 •

Copy link
Copy Markdown
Contributor

Sorry about the delay. I linked this locally to test and found this issue right away: if you open the editor with a single project, and drag that project and drop it onto one of its own subfolders, an error is displayed. We need to not only do nothing on drop in this case, we shouldn't be highlighting / selecting tree view entries as the project is dragged over them.

screen shot 2016-05-02 at 5 08 07 pm

@peterschmidler

Copy link
Copy Markdown

any progress on this? missing it badly ;)

@Ben3eeE

Ben3eeE commented Oct 24, 2016 •

Copy link
Copy Markdown
Contributor

All project folders collapsed and it seems fine(Did not profile just manual testing). Expand one and 💥
drag root 1-2

@BinaryMuse

Copy link
Copy Markdown

@forivall @Ben3eeE This seems to be because we're calling @getPlaceholder().insertBefore/After(element) over and over again from RootDragAndDropHandler#onDragOver even if the drop target index hasn't changed. I recommend the following modification to cache the previous result and bail early if it's the same:

diff --git a/lib/root-drag-and-drop.coffee b/lib/root-drag-and-drop.coffee
index af68e01..829fd15 100644
--- a/lib/root-drag-and-drop.coffee
+++ b/lib/root-drag-and-drop.coffee
@@ -24,6 +24,7 @@ class RootDragAndDropHandler
     @treeView.on 'drop', '.tree-view', @onDrop

   onDragStart: (e) =>
+    @lastDropTargetIndex = null
     e.originalEvent.dataTransfer.setData 'atom-event', 'true'
     projectRoot = $(e.target).closest('.project-root')
     directory = projectRoot[0].directory
@@ -75,6 +76,8 @@ class RootDragAndDropHandler

     newDropTargetIndex = @getDropTargetIndex(e)
     return unless newDropTargetIndex?
+    return if @lastDropTargetIndex is newDropTargetIndex
+    @lastDropTargetIndex = newDropTargetIndex

     @removeDropTargetClasses()

This resolves the jank on my machine.

Finally, I wonder if it makes more sense to put the placeholder above the hovered project if you're on the upper half of the entire entry, not just the header.

dnd-root-half

In that case, we'd additionally need

diff --git a/lib/root-drag-and-drop.coffee b/lib/root-drag-and-drop.coffee
index 829fd15..62edee5 100644
--- a/lib/root-drag-and-drop.coffee
+++ b/lib/root-drag-and-drop.coffee
@@ -157,9 +158,7 @@ class RootDragAndDropHandler

     return 0 unless projectRoot.length

-    element = projectRoot.find('.project-root-header')
-
-    elementCenter = element.offset().top + element.height() / 2
+    elementCenter = projectRoot.offset().top + projectRoot.height() / 2

     if e.originalEvent.pageY < elementCenter
       projectRoots.index(projectRoot)

@forivall

Copy link
Copy Markdown
Contributor Author

@BinaryMuse Hmm, I didn't think that reinserting the same element would cause the issue, and I wasn't seeing jank on my machines (OSX or Linux, stable atom). But cool, that's a simpler solution than what I briefly tried over my lunch break (debouncing).

Also, I originally did have the placeholder position based on the center of the entire entry, but switched it to the header during the phase where on-disk dragging was allowed. 👍 to reverting back to that placeholder positioning.

@Ben3eeE

Ben3eeE commented Oct 25, 2016

Copy link
Copy Markdown
Contributor

@BinaryMuse Nice 👍

I will test this again later tonight to verify functionality and responsiveness on my machine.

@Ben3eeE

Ben3eeE commented Oct 25, 2016

Copy link
Copy Markdown
Contributor

Accidentally did this I don't know what I expected to happen 😆
525 bug

Similarly in reverse:
525 bug 2

@forivall

Copy link
Copy Markdown
Contributor Author

@Ben3eeE Fixed by 7dbae50 😆

@forivall

forivall commented Oct 26, 2016 •

Copy link
Copy Markdown
Contributor Author

@BinaryMuse I also added the change for

Finally, I wonder if it makes more sense to put the placeholder above the hovered project if you're on the upper half of the entire entry, not just the header.

in edf9e5b. Try it out!

@BinaryMuse

BinaryMuse commented Oct 26, 2016 •

Copy link
Copy Markdown

@forivall This looks awesome, great work! I'm going to look into the spec failures (which have nothing to do with your PR) and once that's resolved I'll merge this. 🎉

[Edit] I lied, gonna worry about the Windows stuff later. To the Merge Button!

@BinaryMuse
BinaryMuse merged commit 8ebef1e into atom:master Oct 26, 2016
Ben3eeE added a commit to atom/tabs that referenced this pull request Oct 26, 2016
@JetUni

JetUni commented Oct 28, 2016

Copy link
Copy Markdown

@forivall THANK YOU SO MUCH!!!!! 🎉🎉

@peterschmidler

Copy link
Copy Markdown

How can I use this feature?

@thomasjo

Copy link
Copy Markdown
Contributor

If you want it right now, you'll have to build Atom from source. If you can wait, this will be available in the next beta release.

@forivall

Copy link
Copy Markdown
Contributor Author

@peterschmidler you can also clone this repository and npm install && apm rebuild && apm link .

@winstliu

Copy link
Copy Markdown
Contributor

Or just apm install && apm link.

@BinaryMuse

Copy link
Copy Markdown

Keep in mind that installing the package from a local source via apm link will shadow the built-in package and keep you from using the latest version when Atom updates.

@KSXGitHub

Copy link
Copy Markdown

What about apm install tree-view?

@BinaryMuse

Copy link
Copy Markdown

@KSXGitHub I guess to be more specific, any mechanism by which you place a package with the same name as a core, bundled package in your .atom/packages directory will shadow the bundled package (that's why doing it makes the feature work. :) But if you forget to remove it, Atom will continue to use the one you installed instead of the bundled one, even if the bundled one is newer.

@thomasjo

thomasjo commented Nov 1, 2016

Copy link
Copy Markdown
Contributor

I highly advise people to not install core packages directly — it only leads to tears.

Core packages should only be symlinked in dev mode when you are actively working on the package.

Since this issue has gone completely off-topic, and needlessly notifying 21+ people is unnecessary, I'm locking this thread. If someone wants to discuss this further, do it on the Slack channel or on Discuss 🙇

@atom atom locked and limited conversation to collaborators Nov 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rearrange project folders via drag and drop