fix: require long press to open swipe picker on phones (#5382) * fix: require long press to open swipe picker on phones * fix: clarify parameter description in assignLorebookToChat function * fix: update event parameter type in onSwipeCounterClick to include TouchEvent * fix: update event parameter types in onSwipeCounterClick and addLongPressEvent

d2b2b1b4a60eeea56b38f340e8f0d08faf4e240e

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
4 files changed, +21 -14Ignore whitespace
public/scripts/personas.js+3 -3
@@ -1171,9 +1171,9 @@ function onPersonaDescriptionDepthRoleInput() {
11711171
11721172/**
11731173 * Opens a popup to set the lorebook for the current persona.
11741174 * @param {Pick<JQuery.ClickEvent, 'shiftKey' | 'altKey'>} event Click event
11751175 */
11761176async function onPersonaLoreButtonClick(event{ shiftKey, altKey }) {
11771177 const personaName = power_user.personas[user_avatar];
11781178 const selectedLorebook = power_user.persona_description_lorebook;
11791179
@@ -1182,7 +1182,7 @@ async function onPersonaLoreButtonClick(event) {
11821182 return;
11831183 }
11841184
11851185 if (selectedLorebook && !event.shiftKey && !event.altKey) {
11861186 openWorldInfoEditor(selectedLorebook);
11871187 return;
11881188 }
public/scripts/swipe-picker.js+15 -7
@@ -3,8 +3,9 @@ import { SWIPE_DIRECTION, SWIPE_SOURCE } from './constants.js';
33import { t } from './i18n.js';
44import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js';
55import { power_user } from './power-user.js';
6+import { isMobile } from './RossAscends-mods.js';
67import { getTokenCountAsync } from './tokenizers.js';
78import { addLongPressEvent, clamp, copyText, timestampToMoment } from './utils.js';
89import { chat, deleteSwipe, ensureSwipes, isMessageSwipeable, isSwipingAllowed, swipe, syncMesToSwipe } from '/script.js';
910
1011/**
@@ -409,22 +410,29 @@ async function openSwipePicker(messageId) {
409410}
410411
411412export function initSwipePicker() {
412- $(document).on('click', '.swipes-counter.swipe-picker-enabled', async function (e) {
413+ /**
414+ * Click handler for opening the swipe picker when clicking on the swipe counter.
415+ * @param {JQuery.Event | Event} e Event object
416+ */
417+ async function onSwipeCounterClick(e) {
413418 e.preventDefault();
414419 e.stopPropagation();
415420
416421 const mesId = Number($(this).closest('.mes').attr('mesid'));
417422 await openSwipePicker(mesId);
418423 });
424+
425+ if (isMobile()) {
426+ addLongPressEvent('.swipes-counter.swipe-picker-enabled', onSwipeCounterClick);
427+ } else {
428+ $(document).on('click', '.swipes-counter.swipe-picker-enabled', onSwipeCounterClick);
429+ }
419430 $(document).on('keydown', '.swipes-counter.swipe-picker-enabled', async function (e) {
420431 if (e.key !== ' ') {
421432 return;
422433 }
423434
424435 eonSwipeCounterClick.preventDefaultcall(this, e);
425- e.stopPropagation();
426- const mesId = Number($(this).closest('.mes').attr('mesid'));
427- await openSwipePicker(mesId);
428436 });
429437 $(document).on('click', '.mes_swipe_picker', async function (e) {
430438 e.preventDefault();
public/scripts/utils.js+2 -1
@@ -2955,7 +2955,7 @@ export function createTimeout(ms, errorMessage = '') {
29552955 * Registers a long-press (touch hold) event as an alternative to modifier+click.
29562956 * Supports event delegation for dynamically created elements.
29572957 * @param {string} selector CSS selector for target elements
29582958 * @param {function(e: TouchEvent) => void} callback Callback to invoke on long-press, `this` is the matched element
29592959 * @param {number} [delay=500] Long-press duration in ms
29602960 */
29612961export function addLongPressEvent(selector, callback, delay = 500) {
@@ -2964,6 +2964,7 @@ export function addLongPressEvent(selector, callback, delay = 500) {
29642964 let target = null;
29652965
29662966 document.addEventListener('touchstart', function (event) {
2967+ if (!(event.target instanceof Element)) return;
29672968 const el = event.target.closest(selector);
29682969 if (!el) return;
29692970 target = el;
public/scripts/world-info.js+1 -3
@@ -5808,9 +5808,7 @@ export function openWorldInfoEditor(worldName) {
58085808
58095809/**
58105810 * Assigns a lorebook to the current chat.
5811- * @param {Object} options - The options for assigning the lorebook.
5811+ * @param {Pick<JQuery.ClickEvent, 'shiftKey' | 'altKey'>} event Click event
5812- * @param {boolean} options.shiftKey - Whether the Shift key is pressed.
5813- * @param {boolean} options.altKey - Whether the Alt key is pressed.
58145812 * @returns {Promise<void>}
58155813 */
58165814export async function assignLorebookToChat({ shiftKey, altKey }) {