historyManager getting event even though nothing has changed

Hi

I've recently been added Undo/Redo functionality to my application.

I noticed that sometimes the diagram will log an event when I click on a node even though nothing has changed. The problem is that my Undo button becomes active but there is actually nothing to Undo.

I can demonstrate the issue in this stackblitz:

https://stackblitz.com/edit/stackblitz-starters-jtt4vr?file=src%2Fapp%2Fdiag%2Fdiag.component.ts

I have also recorded the attached video. In the video you can see that I simply click on a node and every once in a while an event gets added to the history.

Image_2466_1722439909675


Attachment: historyVid_940b010d.zip

18 Replies

VG Vivisa Ganesan Syncfusion Team August 1, 2024 11:45 AM UTC

Hi,

Upon analyzing the video you shared, we found that a history entry is added while the position changes. We suspect that the node moves slightly during selection or deselection, it will be added to the history, triggering the event.


Regards

Vivisa



KA Kabe August 1, 2024 01:42 PM UTC

At first that was my thought too. But I don't think so for 2 reasons:

  1. the node is snapping to grid, so no movement shouldn't be getting triggered
  2. see screenshot attached where I've expanded the info in the console. This is 2 events that were captured just by clicking on the node. If I'm reading it correctly the position hasn't changed:
Image_1224_1722519508257

If it is indeed some sort of position change is there a workaround to prevent it from getting logged? I think it is confusing for users to press Undo and not see anything get undone.

Thanks!


VG Vivisa Ganesan Syncfusion Team August 2, 2024 03:11 PM UTC

Hi,

We will validate and update you with more details on August 6,2024.

Regards,

Vivisa



MG Moulidharan Gopalakrishnan Syncfusion Team August 6, 2024 05:16 PM UTC

Hi,


We still cannot reproduce the issue from our end as it occurs on random event. we will further validate and update you with more details on August 8,2024.


Regards,

Moulidharan



VG Vivisa Ganesan Syncfusion Team August 8, 2024 01:22 PM UTC

Hi,


The reported scenario occurs randomly due to the framework's mousemove event, which triggers the diagram's positionChange event. Since this behavior is caused by the framework, setting args.cancel to true in our positionChange events does not resolve the issue. Consequently, it is not feasible to handle this directly within the diagram source. You will need to explore options to prevent the framework's mousemove event from interfering. Unfortunately, we do not have any other solutions available on our end.


Regards,

Vivisa



KA Kabe August 12, 2024 04:02 PM UTC

I've learned about the canLog function (https://ej2.syncfusion.com/angular/documentation/diagram/undo-redo#canlog ) which can be used to cancel additions to the history. I've implement it here:

public created(): void {
    this.diagram.fitToPage();

    this.diagram.historyManager.canLog = (historyEntryHistoryEntry=> {
      console.log(historyEntry);

      //if (this.skipUndoTracking) {
      //console.log('skipped');
      //  historyEntry.cancel = true;
      //}

      return historyEntry;
    };
  }


I feel like there must be a way to set historyEntry.cancel to true if the position change isn't 'real'. 

Can this be used? 



VG Vivisa Ganesan Syncfusion Team August 13, 2024 01:10 PM UTC

Hi,

Yes, you can restrict a history entry from being added when the positionChange event is triggered by using the canLog property. We have modified the sample according to your requirements. Refer to the sample and code snippet below:


Code-snippet:


  public created(): void {

    this.diagram.fitToPage();

 

    this.diagram.historyManager.canLog = (historyEntry: HistoryEntry) => {

      console.log(historyEntry);

      if (historyEntry.type == 'PositionChanged') {

        historyEntry.cancel = true;

      }

      return historyEntry;

    };

  }

 


Sample:

https://stackblitz.com/edit/stackblitz-starters-zkhphg?file=src%2Fapp%2Fdiag%2Fdiag.component.ts


Regards,

Vivisa



KA Kabe August 13, 2024 03:20 PM UTC

Hi - 

I tried your stackblitz and it doesn't work for 2 reasons:

  1. If you add a node and then move it several times (say 5 times) and then try to undo (Ctrl+Z) it should disappear after 1 undo. But you have to press Ctrl+Z 5 times to get the node removed
  2. This code would seem to not track ALL position changes, but what we really want to do is just not track a position change when the position hasn't actually changed
There must be a way to do this? Is there someone else that can help?



VG Vivisa Ganesan Syncfusion Team August 14, 2024 12:28 PM UTC

Hi,

We will validate and update you with more details on August 19,2024.


Regards,

Vivisa



SA Surah Al Waqiah August 15, 2024 05:05 AM UTC

I've noticed the same issue with Undo/Redo functionality where events are logged even without changes, activating the Undo button unnecessarily. It might help to add a condition that checks for actual changes before logging events, preventing the history manager from recording irrelevant actions.

Thanks for sharing the demo and video! 



KA Kabe August 15, 2024 01:52 PM UTC

Hi Surah I agree - I am thinking the same thing but don't have enough knowledge of the inner workings of the events to figure this out so I'll see what they come back with on Aug 19, 2024.





MG Moulidharan Gopalakrishnan Syncfusion Team August 20, 2024 01:15 PM UTC

Hi,

 

Reported Issue: Clear empty history entries in the history manager while cancelling entry using canLog.

 

We can reproduce the issue and confirmed this as a defect. We have logged a defect report for this issue. We will fix this issue and provide the patch on 10th September,2024 weekly patch release.

 

Feedback Link:  https://www.syncfusion.com/feedback/60552/clear-empty-history-entries-in-the-history-manager-while-cancelling-entry-using

 

Disclaimer: Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.

 

 

Regards,

Moulidharan



VG Vivisa Ganesan Syncfusion Team September 10, 2024 03:57 PM UTC

Hi,

We have fixed the issue and provided custom package below. However, we will include the fix for the issue in our upcoming volume 3 release which is scheduled to release on next week.

 


Regards,

Vivisa


Attachment: package_b863d169.zip


SV Sarathkumar V Syncfusion Team September 19, 2024 04:01 PM UTC

Hi,

We have fixed the reported issue and included it in our Essential Studio 2024 Volume 3 Main Release v27.1.48  version. Kindly upgrade to that version to get the issue resolved.

NPM package:
https://www.npmjs.com/package/@syncfusion/ej2-diagrams
https://www.npmjs.com/package/@syncfusion/ej2-angular-diagrams


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.

Regards,

Sarath



AK alihaider khan replied to Vivisa Ganesan December 21, 2024 11:19 AM UTC

Hi Vivisa,

Thanks for the info. Since args.cancel doesn't resolve the issue, I'll explore alternative solutions, like intercepting the mousemove event or checking if the framework offers any settings to control it. I’ll keep you updated.



DP Dhakshin Prasath Dhanraj Syncfusion Team December 23, 2024 11:04 AM UTC

Hi,

 

Thank you for your update. Please feel free to reach out if you need further assistance, we're always happy to help!

 

Regards,

Dhakshin



AK alihaider khan replied to Vivisa Ganesan December 24, 2024 10:18 AM UTC

Hi Vivisa,

Thanks for the update! I appreciate the custom package, and I look forward to the upcoming Volume 3 release next week.

Best regards,



DP Dhakshin Prasath Dhanraj Syncfusion Team December 27, 2024 12:23 PM UTC

Hi,

 

The reported issue is fixed in Volume 3 release and Volume 3 release is rolled out. If you are still facing any issues, please update us. Kindly provide more details on your last query.


Regards,
Dhakshin



Loader.
Up arrow icon