ailon / markerjs2

Add image annotation to your web apps.
https://markerjs.com
Other
143 stars 39 forks source link

Clearing all markers does not dispatch 'delete' event after 'select' event #102

Closed stefan-sl closed 2 years ago

stefan-sl commented 2 years ago

Our implementation of markerjs2 relies on the marker-level events dispatched from the MarkerArea. We've recently added the clear all markers button and there is no final delete or deselect event when you clear all the markers. Using example here: https://codesandbox.io/s/marker-js-2-freehand-from-the-start-forked-gww8j8?file=/src/index.js

To reproduce:

  1. Create an arrow marker on the image
  2. Delete the marker using the trashcan delete button
  3. Observe the console, you will see a 'deselect' and then a 'delete'
  4. Now create a new arrow marker
  5. Select the undo button
  6. Observe the console, you will see a 'deselect' event
  7. Create a new arrow marker
  8. Delete using the delete all broom button
  9. Observe the console, you will see a 'deselect' and then the final event dispatched is a 'select' event which returns a marker that is disposed shortly after the event is dispatched

In our implementation we are relying on these events to determine if other context menus should show/hide. Because the last event dispatched on delete all is 'select' we cannot accurately determine how to configure our menus because 'select' implies that a marker is still selected when that is not true.

Is it possible to either dispatch a 'delete' event or another new event when all markers are cleared?

ailon commented 2 years ago

Hi @stefan-sl,

Thank you for the detailed repro!

Yes, I see the issue and will fix it in the next release by firing a delete event on each marker removed. Need to let it "marinate" for a couple of days and think if it won't cause any negative side-effects.