Skip to content

Commit

Permalink
Only redraw on canvas mouseout if event was triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed May 27, 2024
1 parent f27b13c commit 513919d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/jcanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,15 @@ function _addLayerEvents(
}
if (!data.events.mouseout) {
$canvas.on("mouseout.jCanvas", function () {
let shouldRedraw = false;
// Retrieve the layer whose drag event was canceled
const dragLayer = data.drag.layer;
// If cursor mouses out of canvas while dragging
if (dragLayer) {
// Cancel drag
data.drag = { layer: null, dragging: false };
_triggerLayerEvent($canvas, data, dragLayer, "dragcancel");
shouldRedraw = true;
}
// Loop through all layers
for (let l = 0; l < data.layers.length; l += 1) {
Expand All @@ -666,10 +668,13 @@ function _addLayerEvents(
if (layer && layer._hovered) {
// Trigger mouseout on layer
$canvas.triggerLayerEvent(data.layers[l], "mouseout");
shouldRedraw = true;
}
}
// Redraw layers
$canvas.drawLayers();
// Redraw layers only if an event has been triggered
if (shouldRedraw) {
$canvas.drawLayers();
}
});
// Indicate that an event handler has been bound
data.events.mouseout = true;
Expand Down

0 comments on commit 513919d

Please sign in to comment.