feat: Remember the tranbox position and size

This commit is contained in:
Gabe
2025-10-25 23:18:39 +08:00
parent 5550f939b2
commit 1b646df908
3 changed files with 33 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ import {
import { isMobile } from "../../libs/mobile";
import { kissLog } from "../../libs/log";
import { useLangMap } from "../../hooks/I18n";
import { debouncePutTranBox, getTranBox } from "../../libs/storage";
export default function Slection({
contextMenuType,
@@ -107,6 +108,29 @@ export default function Slection({
return "onMouseUp";
}, [triggerMode]);
useEffect(() => {
(async () => {
try {
const { w, h, x, y } = (await getTranBox()) || {};
if (w !== undefined && h !== undefined) {
setBoxSize({ w, h });
}
if (x !== undefined && y !== undefined) {
setBoxPosition({
x: limitNumber(x, 0, window.innerWidth),
y: limitNumber(y, 0, window.innerHeight),
});
}
} catch (err) {
//
}
})();
}, []);
useEffect(() => {
debouncePutTranBox({ ...boxSize, ...boxPosition });
}, [boxSize, boxPosition]);
useEffect(() => {
async function handleMouseup(e) {
e.stopPropagation();