Skip to content

Commit

Permalink
Fixed bugs: color palette full clear on smartphone, canvas snapshot b…
Browse files Browse the repository at this point in the history
…ugs.
  • Loading branch information
EtherCD committed Sep 15, 2024
1 parent c28ec7d commit c491256
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/components/Windows/Palette/ColorDelete/ColorDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Icon } from "../../../General/Icon/Icon";
export function ColorDelete() {
const palette = useContext(PaletteContext);
const [shift, setShift] = useState<boolean>(false);
const touchTimerRef = useRef<NodeJS.Timeout>();

function onClick(event: MouseEvent) {
if (event.shiftKey) {
Expand All @@ -21,6 +22,19 @@ export function ColorDelete() {
setShift(event.shiftKey);
}

function onTouchStart(event: TouchEvent) {
event.preventDefault();
if (touchTimerRef.current) clearTimeout(touchTimerRef.current);
touchTimerRef.current = setTimeout(() => {
palette.reset();
}, 500);
}

function onTouchEnd(event: TouchEvent) {
event.preventDefault();
if (touchTimerRef.current) clearTimeout(touchTimerRef.current);
}

useEffect(() => {
document.addEventListener("keydown", onKeyEvent);
document.addEventListener("keyup", onKeyEvent);
Expand All @@ -32,7 +46,14 @@ export function ColorDelete() {
}, []);

return (
<button className={styles.button} onClick={onClick} disabled={!(shift || !palette.isDefaultColor(palette.palette.value.selected))}>
<button
className={styles.button}
onClick={onClick}
// disabled={!(shift || !palette.isDefaultColor(palette.palette.value.selected))}
onTouchStart={onTouchStart}
onTouchCancel={onTouchEnd}
onTouchEnd={onTouchEnd}
>
<Icon icon="plus" className={styles.icon} alt={"Удалить выбранный цвет"} />
</button>
);
Expand Down
5 changes: 3 additions & 2 deletions src/managers/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export const SnapshotManager = {
if (width < 0) {
width = Math.abs(width);
changed = true;
offsetPoint.x = point.x + 1;
offsetPoint.x = point.x;
} else if (!Number.isNaN(offsetPoint.x)) {
offsetPoint.x = NaN;
changed = true;
}
if (height < 0) {
height = Math.abs(height);
changed = true;
offsetPoint.y = point.y + 1;
offsetPoint.y = point.y;
} else if (!Number.isNaN(offsetPoint.y)) {
offsetPoint.y = NaN;
changed = true;
Expand All @@ -93,6 +93,7 @@ export const SnapshotManager = {
this.stop();
this.size.value = new Point(image.size.x, image.size.y);
this.toClipboard();
this.empty.value = false;
},

async toClipboard(scaleLimit = 10) {
Expand Down

0 comments on commit c491256

Please sign in to comment.