From 16cf9ee1edab4bbaf3c3febe873537e9655a8bbe Mon Sep 17 00:00:00 2001 From: Gabe Yuan Date: Mon, 25 Dec 2023 17:21:59 +0800 Subject: [PATCH] feat: toto: selection translation on mobile support --- src/views/Selection/TranBtn.js | 14 ++++++++++---- src/views/Selection/index.js | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/views/Selection/TranBtn.js b/src/views/Selection/TranBtn.js index d140c59..bbf1b3b 100644 --- a/src/views/Selection/TranBtn.js +++ b/src/views/Selection/TranBtn.js @@ -1,4 +1,5 @@ import { limitNumber } from "../../libs/utils"; +import { isMobile } from "../../libs/mobile"; export default function TranBtn({ onClick, position, tranboxSetting }) { const left = limitNumber( @@ -12,6 +13,14 @@ export default function TranBtn({ onClick, position, tranboxSetting }) { document.body.scrollHeight - 20 ); + const touchProps = isMobile + ? { + onTouchEnd: onClick, + } + : { + onMouseUp: onClick, + }; + return (
{ - e.stopPropagation(); - }} + {...touchProps} > { async function handleMouseup(e) { + e.stopPropagation(); await sleep(10); const selectedText = window.getSelection()?.toString()?.trim() || ""; @@ -64,7 +65,9 @@ export default function Slection({ contextMenus, tranboxSetting, transApis }) { setPosition({ x: pageX, y: pageY }); } - window.addEventListener(isMobile ? "touchend" : "mouseup", handleMouseup); + // TODO: mobile support + window.addEventListener("mouseup", handleMouseup); + // window.addEventListener(isMobile ? "touchend" : "mouseup", handleMouseup); return () => { window.removeEventListener( isMobile ? "touchend" : "mouseup",