Skip to content

Commit

Permalink
fix: Avoid completed event on outside boundary element (#1256)
Browse files Browse the repository at this point in the history
When drawing an annotation, if it's outside the boundary of the image data, it is removed (depending on your settings).
Because of the order of our callbacks, this would allow for the following scenario:

- Begin drawing annotation
- Drag end handle off image data
- Mouseup with end handle off image data
- Measurement removed from toolstate
- Measurement completed

3rd party applications listening to events might think the measurement was sucessfully created. This change ensures measurementData marked as "canceled" will not emit a "completed" event (at least via manipulator default callbacks)
  • Loading branch information
igoroctaviano authored Jun 30, 2020
1 parent aa54b30 commit c9e6fa3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/eventDispatchers/mouseEventHandlers/addNewMeasurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default function(evt, tool) {
tool.options,
'mouse',
() => {
if (measurementData.cancelled) {
return;
}

const eventType = EVENTS.MEASUREMENT_COMPLETED;
const eventData = {
toolName: tool.name,
Expand Down
1 change: 1 addition & 0 deletions src/manipulators/moveNewHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ function _moveEndHandler(
options.deleteIfHandleOutsideImage &&
anyHandlesOutsideImage(evt.detail, annotation.handles)
) {
annotation.cancelled = true;
removeToolState(element, toolName, annotation);
}

Expand Down

0 comments on commit c9e6fa3

Please sign in to comment.