Simplified code by removing boxKeys array

pull/3559/head
stweedo 2024-09-06 08:21:00 -05:00 committed by GitHub
parent 48e02ba13f
commit 5f6fd9247d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 43 additions and 42 deletions

View File

@ -28,19 +28,20 @@
let boxTouched = false;
let touchedBox = null;
boxKeys.forEach((boxKey) => {
if (touchInText(e, boxes[boxKey], boxKey)) {
for (let boxKey in boxes) {
if (touchInText(e, boxes[boxKey])) {
touchedBox = boxKey;
boxTouched = true;
break;
}
}
});
if (boxTouched) {
// Toggle the selected state of the touched box
boxes[touchedBox].selected = !boxes[touchedBox].selected;
// Update isDragging based on whether any box is selected
isDragging = boxKeys.some(key => boxes[key].selected);
isDragging = Object.values(boxes).some(box => box.selected);
if (isDragging) {
widgets.hide();
@ -60,10 +61,10 @@
if (doubleTapTimer) {
clearTimeout(doubleTapTimer);
doubleTapTimer = null;
Object.keys(boxes).forEach((boxKey) => {
for (let boxKey in boxes) {
boxesConfig[boxKey].boxPos.x = (boxes[boxKey].pos.x / w).toFixed(3);
boxesConfig[boxKey].boxPos.y = (boxes[boxKey].pos.y / h).toFixed(3);
});
}
storage.write(fileName, JSON.stringify(boxesConfig));
displaySaveIcon();
return;
@ -82,7 +83,7 @@
// Stop propagation of the drag event to prevent other handlers
E.stopEventPropagation();
boxKeys.forEach(key => {
for (let key in boxes) {
if (boxes[key].selected) {
let boxItem = boxes[key];
calcBoxSize(boxItem);
@ -97,7 +98,7 @@
boxItem.pos.y = newY;
}
}
});
}
draw();
};
@ -311,7 +312,7 @@
updateBoxData();
}
boxKeys.forEach((boxKey) => {
for (let boxKey in boxes) {
let boxItem = boxes[boxKey];
// Set font and alignment for each box individually
@ -333,7 +334,7 @@
boxItem.pos.x + boxItem.xOffset,
boxItem.pos.y + boxItem.yOffset
);
});
}
if (!isDragging) {
if (drawTimeout) clearTimeout(drawTimeout);
@ -375,7 +376,7 @@
return boxItem.cachedSize;
};
let touchInText = function(e, boxItem, boxKey) {
let touchInText = function(e, boxItem) {
calcBoxSize(boxItem);
const pos = calcBoxPos(boxItem);
return e.x >= pos.x1 &&
@ -386,9 +387,9 @@
let deselectAllBoxes = function() {
isDragging = false;
boxKeys.forEach((boxKey) => {
for (let boxKey in boxes) {
boxes[boxKey].selected = false;
});
}
restoreSetColor();
widgets.show();
widgets.swipeOn();