Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

click_handlers: Use `mouse_drag` instead of `getSelection().type`.

apoorvapendse806cbc731996
diff --git a/web/src/click_handlers.ts b/web/src/click_handlers.ts
index 741a8e124b5..0eb34be1493 100644
--- a/web/src/click_handlers.ts
+++ b/web/src/click_handlers.ts
@@ -175,7 +175,7 @@ export function initialize(): void {
return false;
}
- const select_message_function = function (this: HTMLElement, e: JQuery.TriggeredEvent): void {
+ const select_message_function = function (this: HTMLElement, e: JQuery.ClickEvent): void {
assert(e.target instanceof Element);
if (is_clickable_message_element($(e.target))) {
// If this click came from a hyperlink, don't trigger the
@@ -190,8 +190,10 @@ export function initialize(): void {
return;
}
- if (document.getSelection()?.type === "Range") {
+ if (mouse_drag.is_drag(e)) {
// Drags on the message (to copy message text) shouldn't trigger a reply.
+ // This also prevents triggering a reply when you click and drag through
+ // an area that doesn't contain text.
return;
}
@@ -435,7 +437,7 @@ export function initialize(): void {
return;
}
e.preventDefault();
- if (document.getSelection()?.type === "Range") {
+ if (mouse_drag.is_drag(e)) {
return;
}
const row_id = get_row_id_for_narrowing(this);
@@ -461,7 +463,7 @@ export function initialize(): void {
if ($(e.target).parents(".user-profile-picture").length === 1) {
return;
}
- if (document.getSelection()?.type === "Range") {
+ if (mouse_drag.is_drag(e)) {
// To avoid the click behavior if a user name or status text is
// selected.
e.preventDefault();
diff --git a/web/src/drafts_overlay_ui.ts b/web/src/drafts_overlay_ui.ts
index 0eef9c2f593..cffec68e718 100644
--- a/web/src/drafts_overlay_ui.ts
+++ b/web/src/drafts_overlay_ui.ts
@@ -15,6 +15,7 @@ import * as drafts from "./drafts.ts";
import {$t} from "./i18n.ts";
import * as message_view from "./message_view.ts";
import * as messages_overlay_ui from "./messages_overlay_ui.ts";
+import * as mouse_drag from "./mouse_drag.ts";
import * as overlays from "./overlays.ts";
import * as people from "./people.ts";
import * as rendered_markdown from "./rendered_markdown.ts";
@@ -292,7 +293,7 @@ function render_widgets(
function setup_event_handlers(): void {
$("#drafts_table .restore-overlay-message").on("click", function (e) {
- if (document.getSelection()?.type === "Range") {
+ if (mouse_drag.is_drag(e)) {
return;
}
@@ -313,7 +314,7 @@ function setup_event_handlers(): void {
"click",
".user-group-mention",
function (this: HTMLElement, e) {
- if (document.getSelection()?.type === "Range") {
+ if (mouse_drag.is_drag(e)) {
return;
}
diff --git a/web/src/scheduled_messages_overlay_ui.ts b/web/src/scheduled_messages_overlay_ui.ts
index 4d250122556..0fdf1cae447 100644
--- a/web/src/scheduled_messages_overlay_ui.ts
+++ b/web/src/scheduled_messages_overlay_ui.ts
@@ -6,6 +6,7 @@ import render_scheduled_messages_overlay from "../templates/scheduled_messages_o
import * as browser_history from "./browser_history.ts";
import * as messages_overlay_ui from "./messages_overlay_ui.ts";
+import * as mouse_drag from "./mouse_drag.ts";
import * as overlays from "./overlays.ts";
import * as people from "./people.ts";
import * as scheduled_messages from "./scheduled_messages.ts";
@@ -172,7 +173,7 @@ export function remove_scheduled_message_id(scheduled_msg_id: number): void {
export function initialize(): void {
$("body").on("click", ".scheduled-message-row .restore-overlay-message", (e) => {
- if (document.getSelection()?.type === "Range") {
+ if (mouse_drag.is_drag(e)) {
return;
}
diff --git a/web/src/user_card_popover.ts b/web/src/user_card_popover.ts
index 48353fc71dd..6e236b13f0d 100644
--- a/web/src/user_card_popover.ts
+++ b/web/src/user_card_popover.ts
@@ -557,7 +557,7 @@ export function unsaved_message_user_mention_event_handler(
this: HTMLElement,
e: JQuery.ClickEvent,
): void {
- if (document.getSelection()?.type === "Range") {
+ if (mouse_drag.is_drag(e)) {
return;
}