feat: toto: selection translation on mobile support
This commit is contained in:
@@ -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 (
|
||||
<div
|
||||
style={{
|
||||
@@ -21,10 +30,7 @@ export default function TranBtn({ onClick, position, tranboxSetting }) {
|
||||
top,
|
||||
zIndex: 2147483647,
|
||||
}}
|
||||
onClick={onClick}
|
||||
onMouseUp={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
{...touchProps}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
|
||||
@@ -49,6 +49,7 @@ export default function Slection({ contextMenus, tranboxSetting, transApis }) {
|
||||
|
||||
useEffect(() => {
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user