Skip to content

Conversation

@v1talii-dev
Copy link
Contributor

@v1talii-dev v1talii-dev commented Dec 12, 2023

Description

If you quickly drag elements between nested blocks, duplicates of the same element appear. fix #2560

} else if (node._isExternal) {
// item came from outside (like a toolbar) so nuke any node info
delete node.el;
delete el.gridstackNode;
Copy link
Member

Choose a reason for hiding this comment

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

doesn't make sense to delete one and not the other... will have to debug the code for that particular case and make sure it doesn't break other cases..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I noticed errors in the console and problems with blocks not being deleted after dragging. Restored this function.

src/gridstack.ts Outdated

// if the item came from another grid, make a copy and save the original info in case we go back there
if (node.grid && node.grid !== this) {
if (node.grid !== this) {
Copy link
Member

Choose a reason for hiding this comment

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

still doesn't feel right to me without debuging the issue - if node doesn't have grid, we go through that logic which doesn't feel right...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you. Now it seems to me that the problem is not in this place at all, but in calling the mouseEnter event in mouseOver. If you comment on this line as a definition of the source of the problem, then everything works correctly - https://github.com/gridstack/gridstack.js/blob/master/src/dd-droppable.ts#L135

@v1talii-dev
Copy link
Contributor Author

v1talii-dev commented Dec 19, 2023

Redid PR. I discovered a bug of redundant event calling. When the "mouseenter" event was called, the "mouseleave" event was called inside that event. That is, they cleared the previous location of the block and showed a new one. The "mouseleave" event contains the logic for inserting a location into the parent (when we drag the block up into the parent). So, we got a situation where we dragged a field to a child, and the “mouseenter” event was triggered, in turn, “mouseleave” was called, and then “mouseenter” was called. Removed the redundant "mouseenter" step specifically for the program call (the behavior when moving the mouse was preserved). Sorry for my English, I use google translate.

this.triggerEvent('dropout', ev);

if (DDManager.dropElement === this) {
if (!external && DDManager.dropElement === this) {
Copy link
Member

Choose a reason for hiding this comment

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

DDManager.dropElement === this can be removed since on line 113


if (DDManager.dropElement === this) {
if (!external && DDManager.dropElement === this) {
delete DDManager.dropElement;
Copy link
Member

Choose a reason for hiding this comment

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

this should still happen. move to line 114.
rename the var fromParent and instead the next comment should be:
// if we're still over a parent droppable, send it an enter as we don't get one from leaving nested children if it's not already calling us
if (!fromParent) {
let parentDrop: DDDroppable;
let parent: DDElementHost = this.el.parentElement;
....

@adumesny adumesny merged commit 3ea8fbe into gridstack:master Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copies are added after quickly dragging elements in the subgrid

2 participants