Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
mouse_drag: Ignore keyboard clicks in drag detection.
Shubham Padiaf366f4ea231b
diff --git a/web/src/mouse_drag.ts b/web/src/mouse_drag.tsindex f332296e1a6..27823824c20 100644--- a/web/src/mouse_drag.ts+++ b/web/src/mouse_drag.ts@@ -4,9 +4,9 @@ let start_x = 0;let start_y = 0;export function initialize(): void {- $(document).on("mousedown", (e) => {- start_x = e.pageX;- start_y = e.pageY;+ $(document).on("pointerdown", (e) => {+ start_x = e.pageX ?? 0;+ start_y = e.pageY ?? 0;});}@@ -14,24 +14,17 @@ 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;}+ // Modern browsers dispatch click as a PointerEvent. Keyboard-+ // triggered clicks (e.g. Enter on a focused link) have an empty+ // pointerType, so we can skip drag detection for them.+ if (e.originalEvent instanceof PointerEvent && e.originalEvent.pointerType === "") {+ 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);