Skip to content

Commit 732629a

Browse files
authored
Merge pull request #3104 from j6k4m8/fix-mousebutton-lag
Add inline docs to mousePressed listener
2 parents 482cd72 + 9fe6970 commit 732629a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/core/p5.Element.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,16 @@ p5.Element.prototype.class = function(c) {
232232
*
233233
*/
234234
p5.Element.prototype.mousePressed = function(fxn) {
235+
// Prepend the mouse property setters to the event-listener.
236+
// This is required so that mouseButton is set correctly prior to calling the callback (fxn).
237+
// For details, see https://github.com/processing/p5.js/issues/3087.
235238
var eventPrependedFxn = function(event) {
236239
this._pInst._setProperty('mouseIsPressed', true);
237240
this._pInst._setMouseButton(event);
241+
// Pass along the return-value of the callback:
238242
return fxn();
239243
};
244+
// Pass along the event-prepended form of the callback.
240245
adjustListener('mousedown', eventPrependedFxn, this);
241246
return this;
242247
};

0 commit comments

Comments
 (0)