Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/events/mouse.js
Original file line number Diff line number Diff line change
@@ -341,7 +341,7 @@ p5.prototype.pwinMouseY = 0;
/**
* p5 automatically tracks if the mouse button is pressed and which
* button is pressed. The value of the system variable mouseButton is either
* LEFT, RIGHT, or CENTER depending on which button was pressed last.
* LEFT, RIGHT, or CENTER depending on which button was pressed/released last.
* Warning: different browsers may track mouseButton differently.
*
* @property {Constant} mouseButton
@@ -734,6 +734,7 @@ p5.prototype._onmouseup = function(e) {
const context = this._isGlobal ? window : this;
let executeDefault;
this._setProperty('mouseIsPressed', false);
this._setMouseButton(e);

// _ontouchend triggers first and sets this.touchend
if (this.touchend) {
8 changes: 8 additions & 0 deletions test/unit/events/mouse.js
Original file line number Diff line number Diff line change
@@ -365,6 +365,14 @@ suite('Mouse Events', function() {
assert.deepEqual(count, 1);
});

test('mouseButton should be "left" on left mouse button release', async function() {
// both mouse buttons pressed
window.dispatchEvent(new MouseEvent('mousedown', { button: 0 }));
window.dispatchEvent(new MouseEvent('mousedown', { button: 2 }));
window.dispatchEvent(new MouseEvent('mouseup', { button: 0 }));
assert.strictEqual(myp5.mouseButton, 'left');
});

test('mouseReleased functions on multiple instances must run once', async function() {
let sketchFn = function(sketch, resolve, reject) {
let count = 0;