Limit the mobile Quick Action's activation area to the app header

Save this as a .js file and point CodeScript ToolKit to it as your “Startup script path.” It’ll make it so the mobile Quick Action no longer gets activated when swiping in note/text area, but you still can activate it by swiping down from the app header.

exports.invoke = async (app) => {
	if (window.__swipe_hook_installed || !app.isMobile) return;

	function hookSwipe(thing) {
		if (!thing) return;
		const proto = Object.getPrototypeOf(thing);
		if (!proto || typeof proto.trigger !== "function" || proto.trigger.__swipe_hooked) return;

		const orig = proto.trigger;
		proto.trigger = function (eventName, data) {
			try {
				if (eventName === "swipe" && data && data.direction === "y") {
					const isDown = data.y && data.startY && data.y > data.startY;
					if (isDown) {
						const el = data.targetEl || data.touch?.target || data.evt?.target || null;
						const insideEditor = el?.closest?.('.view-content');

						if (insideEditor) {
							return;
						}
					}
				}
			} catch (err) {
				console.error(err);
			}
			return orig.apply(this, arguments);
		};

		proto.trigger.__swipe_hooked = true;
	}

	const thingsToHookInto = [app?.workspace, app?.workspace?.rootSplit, app?.workspace?.activeLeaf];

	for (const thing of thingsToHookInto) hookSwipe(thing);
	window.__swipe_hook_installed = true;
}

Relevant feature requests:

1 Like