Skip to content

Commit

Permalink
fix: generalize fix for swallowed hover events
Browse files Browse the repository at this point in the history
Replaces the old drag hover fix (which fixed kindof the same thing)
with one that works in a general fashion only on element.* level.

Closes bpmn-io/bpmn-js#1366

----

MISSING:

* tests
  • Loading branch information
nikku committed Nov 26, 2020
1 parent fbce7d1 commit b1bb1e2
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 deletions lib/features/dragging/HoverFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,59 +79,48 @@ export default function HoverFix(eventBus, dragging, elementRegistry) {


/**
* We make sure that drag.out is always fired, even if the
* We make sure that element.out is always fired, even if the
* browser swallows an element.out event.
*
* Event sequence:
*
* drag.hover
* element.hover
* (element.out >> sometimes swallowed)
* element.hover >> ensure we fired drag.out
* element.hover >> ensure we fired element.out
*/
eventBus.on('drag.init', function() {
(function() {
var hoverGfx;
var hover;

var hover, hoverGfx;
eventBus.on('element.hover', function(event) {

function setDragHover(event) {
hover = event.hover;
hoverGfx = event.hoverGfx;
}
// (1) remember current hover element
hoverGfx = event.gfx;
hover = event.element;
});

function unsetHover() {
hover = null;
hoverGfx = null;
}
eventBus.on('element.hover', HIGH_PRIORITY, function(event) {

function ensureOut() {
// (3) am I on an element still?
if (hover) {

if (!hover) {
return;
// (4) that is a problem, gotta "simulate the out"
eventBus.fire('element.out', {
element: hover,
gfx: hoverGfx
});
}

var element = hover,
gfx = hoverGfx;

hover = null;
hoverGfx = null;

// emit synthetic out event
dragging.out({
element: element,
gfx: gfx
});
}
});

eventBus.on('drag.hover', setDragHover);
eventBus.on('element.out', unsetHover);
eventBus.on('element.hover', HIGH_PRIORITY, ensureOut);
eventBus.on('element.out', function() {

eventBus.once('drag.cleanup', function() {
eventBus.off('drag.hover', setDragHover);
eventBus.off('element.out', unsetHover);
eventBus.off('element.hover', ensureOut);
// (2) unset hover state if we correctly outed us *GG*
hoverGfx = null;
hover = null;
});

});
})();

this._findTargetGfx = function(event) {
var position,
Expand Down

0 comments on commit b1bb1e2

Please sign in to comment.