-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix BUG: Dragging multiple blocks reverses the order #3547 #4220
Conversation
Here is what I did:
I'd appreciate any feedback on the code or tests to make sure I didn't break anything @japo32 ? Also I did not create any tests because I couldn't find a suitable place, should I @artf ? Here is how it behaves now: Uploading 2022-03-29 12-50-56.mp4… |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lexoyo thanks for the PR.
I'd say I'd not expect any change in MoveComponent
and I'd not rely on DOM for sorting as it might differ from the component tree (the component view can be completely custom).
I think this issue might be solved on the sorter level by relying on the component methods like component.index()
and component.parent()
.
Here what I'd expect from a simple sort by component index.
const toMoveArr = ...;
if (toMoveArr.length > 1) {
toMoveArr.sort((a, b) => {
// inverted sort as we append always to the same lastPos
return b.index() - a.index();
})
}
toMoveArr.forEach(model => { ...
This obviously doesn't count the sort across different parents which is probably the main reason I always postponed this fix 😅
d0b37a0
to
49f3214
Compare
Hi @artf , thx for the quick reply
It makes sense of course !
Ok, very feasable, I did this
I did it like this, but then the problem is when we drop in the same container, after the elements, they get inverted This is why this commit is needed You can test it here, I am still testing it too PS: Sorry for the useless mess in some files, due to linter, I'll clean it at one point, the only changes I made are in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks to work pretty well 👏
@artf I took into account your review I reverted For your last 2 comments, I think I got it, please confirm. I have tested dropping images, now it works :)) |
also i updated https://lexoyo.me/grapesjs/demo.html |
Awesome, thank you @lexoyo ❤️ |
Hello
I'm trying to fix #3547
This is more of an exercise for me to dive in grapesjs code, let me know if I'm loosing my time or if it sounds useful