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
This commit is contained in:
@@ -1171,9 +1171,9 @@ function onPersonaDescriptionDepthRoleInput() {
|
||||
|
||||
/**
|
||||
* Opens a popup to set the lorebook for the current persona.
|
||||
* @param {JQuery.ClickEvent} event Click event
|
||||
* @param {Pick<JQuery.ClickEvent, 'shiftKey' | 'altKey'>} event Click event
|
||||
*/
|
||||
async function onPersonaLoreButtonClick(event) {
|
||||
async function onPersonaLoreButtonClick({ shiftKey, altKey }) {
|
||||
const personaName = power_user.personas[user_avatar];
|
||||
const selectedLorebook = power_user.persona_description_lorebook;
|
||||
|
||||
@@ -1182,7 +1182,7 @@ async function onPersonaLoreButtonClick(event) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedLorebook && !event.shiftKey && !event.altKey) {
|
||||
if (selectedLorebook && !shiftKey && !altKey) {
|
||||
openWorldInfoEditor(selectedLorebook);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ import { SWIPE_DIRECTION, SWIPE_SOURCE } from './constants.js';
|
||||
import { t } from './i18n.js';
|
||||
import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js';
|
||||
import { power_user } from './power-user.js';
|
||||
import { isMobile } from './RossAscends-mods.js';
|
||||
import { getTokenCountAsync } from './tokenizers.js';
|
||||
import { clamp, copyText, timestampToMoment } from './utils.js';
|
||||
import { addLongPressEvent, clamp, copyText, timestampToMoment } from './utils.js';
|
||||
import { chat, deleteSwipe, ensureSwipes, isMessageSwipeable, isSwipingAllowed, swipe, syncMesToSwipe } from '/script.js';
|
||||
|
||||
/**
|
||||
@@ -409,22 +410,29 @@ async function openSwipePicker(messageId) {
|
||||
}
|
||||
|
||||
export function initSwipePicker() {
|
||||
$(document).on('click', '.swipes-counter.swipe-picker-enabled', async function (e) {
|
||||
/**
|
||||
* Click handler for opening the swipe picker when clicking on the swipe counter.
|
||||
* @param {JQuery.Event | Event} e Event object
|
||||
*/
|
||||
async function onSwipeCounterClick(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
const mesId = Number($(this).closest('.mes').attr('mesid'));
|
||||
await openSwipePicker(mesId);
|
||||
});
|
||||
}
|
||||
|
||||
if (isMobile()) {
|
||||
addLongPressEvent('.swipes-counter.swipe-picker-enabled', onSwipeCounterClick);
|
||||
} else {
|
||||
$(document).on('click', '.swipes-counter.swipe-picker-enabled', onSwipeCounterClick);
|
||||
}
|
||||
$(document).on('keydown', '.swipes-counter.swipe-picker-enabled', async function (e) {
|
||||
if (e.key !== ' ') {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const mesId = Number($(this).closest('.mes').attr('mesid'));
|
||||
await openSwipePicker(mesId);
|
||||
onSwipeCounterClick.call(this, e);
|
||||
});
|
||||
$(document).on('click', '.mes_swipe_picker', async function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -2955,7 +2955,7 @@ export function createTimeout(ms, errorMessage = '') {
|
||||
* Registers a long-press (touch hold) event as an alternative to modifier+click.
|
||||
* Supports event delegation for dynamically created elements.
|
||||
* @param {string} selector CSS selector for target elements
|
||||
* @param {function} callback Callback to invoke on long-press, `this` is the matched element
|
||||
* @param {(e: TouchEvent) => void} callback Callback to invoke on long-press, `this` is the matched element
|
||||
* @param {number} [delay=500] Long-press duration in ms
|
||||
*/
|
||||
export function addLongPressEvent(selector, callback, delay = 500) {
|
||||
@@ -2964,6 +2964,7 @@ export function addLongPressEvent(selector, callback, delay = 500) {
|
||||
let target = null;
|
||||
|
||||
document.addEventListener('touchstart', function (event) {
|
||||
if (!(event.target instanceof Element)) return;
|
||||
const el = event.target.closest(selector);
|
||||
if (!el) return;
|
||||
target = el;
|
||||
|
||||
@@ -5808,9 +5808,7 @@ export function openWorldInfoEditor(worldName) {
|
||||
|
||||
/**
|
||||
* Assigns a lorebook to the current chat.
|
||||
* @param {Object} options - The options for assigning the lorebook.
|
||||
* @param {boolean} options.shiftKey - Whether the Shift key is pressed.
|
||||
* @param {boolean} options.altKey - Whether the Alt key is pressed.
|
||||
* @param {Pick<JQuery.ClickEvent, 'shiftKey' | 'altKey'>} event Click event
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function assignLorebookToChat({ shiftKey, altKey }) {
|
||||
|
||||
Reference in New Issue
Block a user