Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/events/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,13 @@ function pointer(p5, fn, lifecycles){
*/
fn._onpointerup = function(e) {
let executeDefault;
this.mouseIsPressed = false;

this._activePointers.delete(e.pointerId);

if (this._activePointers.size === 0) {
this.mouseIsPressed = false;
}

this._setMouseButton(e);

this._updatePointerCoords(e);
Expand Down
30 changes: 30 additions & 0 deletions test/unit/events/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,36 @@ suite('Touch Events', function() {
});
});

suite('p5.prototype._onpointerup', function() {
test('should reset mouseIsPressed only once all pointers are released', function() {
window.dispatchEvent(touchEvent1);
window.dispatchEvent(touchEvent2);
assert.strictEqual(myp5.mouseIsPressed, true);

const upEvent1 = new PointerEvent('pointerup', {
pointerId: 1,
clientX: 100,
clientY: 100,
pointerType: 'touch'
});
window.dispatchEvent(upEvent1);

assert.strictEqual(myp5.touches.length, 1);
assert.strictEqual(myp5.mouseIsPressed, true);

const upEvent2 = new PointerEvent('pointerup', {
pointerId: 2,
clientX: 200,
clientY: 200,
pointerType: 'touch'
});
window.dispatchEvent(upEvent2);

assert.strictEqual(myp5.touches.length, 0);
assert.strictEqual(myp5.mouseIsPressed, false);
});
});

suite('p5.prototype._onpointercancel', function() {
test('should remove the cancelled touch from touches', function() {
window.dispatchEvent(touchEvent1);
Expand Down
Loading