From 923d3293cdf9283c19470bcb53d88700a075a962 Mon Sep 17 00:00:00 2001 From: Gabe Yuan Date: Fri, 12 Apr 2024 22:28:40 +0800 Subject: [PATCH] fix: limit selection btn in window & click to hide --- src/views/Selection/TranBtn.js | 13 +++++++++++-- src/views/Selection/index.js | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/views/Selection/TranBtn.js b/src/views/Selection/TranBtn.js index e96e50b..bdd7603 100644 --- a/src/views/Selection/TranBtn.js +++ b/src/views/Selection/TranBtn.js @@ -1,8 +1,17 @@ import { isMobile } from "../../libs/mobile"; +import { limitNumber } from "../../libs/utils"; export default function TranBtn({ onClick, position, tranboxSetting }) { - const left = position.x + tranboxSetting.btnOffsetX; - const top = position.y + tranboxSetting.btnOffsetY; + const left = limitNumber( + position.x + tranboxSetting.btnOffsetX, + 0, + window.innerWidth - 32 + ); + const top = limitNumber( + position.y + tranboxSetting.btnOffsetY, + 0, + window.innerHeight - 32 + ); const touchProps = isMobile ? { diff --git a/src/views/Selection/index.js b/src/views/Selection/index.js index 6942c84..188e91b 100644 --- a/src/views/Selection/index.js +++ b/src/views/Selection/index.js @@ -55,7 +55,7 @@ export default function Slection({ useEffect(() => { async function handleMouseup(e) { e.stopPropagation(); - await sleep(10); + await sleep(100); const selectedText = window.getSelection()?.toString()?.trim() || ""; setSelText(selectedText);