SC.CollectionView - subtle bugs in Drag'n'Drop functionality #573

Closed
ftokarev opened this Issue Aug 8, 2011 · 1 comment

Projects

None yet

2 participants

@ftokarev
ftokarev commented Aug 8, 2011

You can test it here: http://demo.sproutcore.com/drag_list/.

How to reproduce:

  1. Drag from the left to the right first six employees: from Martin Scott to Oscar Martinez.
    The first issue - Oscar Martinez is no longer selected
  2. On the right panel select first five employees and drag them to the bottom of the same panel (after Oscar Martinez)
    The second issue - we got selected only three items, not five
  3. Now drag these five employees back to the top of the right panel:
    Exception thrown: Exception in SC.Drag.mouseUp(acceptDragOperation|performDragOperation): Index out of range

I've tinkered a bit with a code of SC.CollectionView. I guess the problem is in this line " if (i < idx) idx--;": (line 2998):

  data.indexes.forEach(function(i) {
    objects.push(content.objectAt(i-shift));
    content.removeAt(i-shift);
    shift++;
    if (i < idx) idx--;
  }, this);

Though my fixes resulted in other bugs of the same nature.

@publickeating
Member

These turned out to all be problems with the implementation of the demo.

In the delegate method collectionViewPerformDragOperation it removed objects after inserting them, so this needed to be changed to removing objects first and then inserting them in the proper new place. It also failed to allow the REORDER drag operation, by implementing collectionViewValidateDragOperation.

I'll be pushing an updated demo to the Showcase in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment