mobile_web: Persist text selection on longtap.

This change enables mobile web users to select text
from messages which lets them do standard text selection
stuff like copy, select + quote, etc.

Previously, this was not possible as long tapping
text content resulted in triggering the reply action
behavior, which included removal of all selection ranges
caused by longtaps.

The possible drawback is not being able long tap a
message in a narrow to reply to the associated
topic/dm.
As an alternative, that can be achieved by a
short tap on the message and then tapping
the composebox.

Fixes: https://chat.zulip.org/#narrow/channel/9-issues/topic/Cannot.20select.20text.20in.20mobile.20web/with/2277387

Frontend discussion: https://chat.zulip.org/#narrow/channel/6-frontend/topic/Simulating.20text.20selection.20on.20Chrome.20DevTools.20for.20mobile.2E/with/2278441

Design discussion: https://chat.zulip.org/#narrow/channel/101-design/topic/Text.20selection.20UX.20on.20mobile.20web/with/2278584

Signed-off-by: apoorvapendse <apoorvavpendse@gmail.com>
This commit is contained in:
apoorvapendse 2025-10-16 18:02:38 +05:30 committed by Tim Abbott
parent 750a07fd0b
commit d512e9a7c9

View File

@ -220,22 +220,6 @@ export function initialize(): void {
// selection function which will open the compose box and select the message.
if (!util.is_mobile()) {
$("#main_div").on("click", ".messagebox", select_message_function);
// on the other hand, on mobile it should be done with a long tap.
} else {
$("#main_div").on("longtap", ".messagebox", function (this: HTMLElement, e) {
const sel = window.getSelection();
// if one matches, remove the current selections.
// after a longtap that is valid, there should be no text selected.
if (sel) {
if (sel.removeAllRanges) {
sel.removeAllRanges();
} else if (sel.empty) {
sel.empty();
}
}
select_message_function.call(this, e);
});
}
$("#main_div").on("click", ".star_container", function (e) {