Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
mouse_drag: Don't treat JS triggered click events as mouse events.
Aman Agrawal12028112f203
diff --git a/web/src/mouse_drag.ts b/web/src/mouse_drag.tsindex dd9dbf417cc..f332296e1a6 100644--- a/web/src/mouse_drag.ts+++ b/web/src/mouse_drag.ts@@ -14,6 +14,24 @@ export function is_drag(e: JQuery.ClickEvent): boolean {// Used to prevent click handlers from firing when dragging a// region, even if not actually selecting something.+ // It is possible to trigger mouse events programmatically+ // via EventTarget.dispatchEvent() or jQuery.trigger or Element.click.+ // Such events have the isTrusted property set to false.+ //+ // The isTrusted read-only property of the Event interface is a boolean+ // value that is true when the event was generated by the user agent+ // (including via user actions and programmatic methods such as+ // HTMLElement.focus()), and false when the event was dispatched via+ // EventTarget.dispatchEvent(). The only exception is the click event,+ // which initializes the isTrusted property to false in user agents.+ // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted+ //+ // We want to ignore programmatically triggered events as much as possible+ // to avoid them being misclassified as drags.+ if (!e.originalEvent?.isTrusted) {+ return false;+ }+// Total distance the mouse has moved since the mouse went down.const drag_distance = Math.abs(e.pageX - start_x) + Math.abs(e.pageY - start_y);