svelte-sortable-list icon indicating copy to clipboard operation
svelte-sortable-list copied to clipboard

Unexpected sorting method

Open gufoscuro opened this issue 5 years ago • 3 comments
trafficstars

Hello! Great component, thanks for your work!

I could be wrong on this, but let me explain my doubt. Let's say I have a list of 3 elements

  • Element 1
  • Element 2
  • Element 3

As soon as I click on Element 1 and I drag it down over Element 3, my expectation is that the Element 1 goes at third position (and that happens) however what usually happens in a sorting list is that Element 3 should shift up to the second position, instead of swapping its position with the first element

To be clear the list after the sort appears this way:

  • Element 3
  • Element 2
  • Element 1

Though I would expect this:

  • Element 2
  • Element 3
  • Element 1

Does this make sense? I guess it could be probably be achieved with #3

thank you! :)

gufoscuro avatar Jul 07 '20 17:07 gufoscuro

I wanted the same behavior so I took #3 and made it into its own fork: https://github.com/Gjum/svelte-dragdrop-list

Gjum avatar Jul 07 '20 22:07 Gjum

@Gjum Using your repo now! It's really nice. I hope your pull request gets accepted soon.

iandoesallthethings avatar Sep 28 '21 20:09 iandoesallthethings

I think its best to make a prop called behaviour that chooses the function based on string "swap"/"sort" or may be a custom function!! for
behaviour="swap" 1,2,3 to 3,2,1 (click:1, up:3)

    const swapElements=()=>{
        const temp=list[pick];
        list.splice(pick,1,list[replace]);
        list.splice(replace,1,temp);
        list=list;
    }

behaviour="reinsert" 1,2,3 to 2,3,1 (click:1, up:3)

    const reinsertElements=()=>{
        const temp=list[pick];
        list.splice(pick,1);
        list.splice(replace,0,temp);
        list=list;
    }

rudrakpatra avatar Feb 13 '22 06:02 rudrakpatra