Skip to content

Commit 29ef513

Browse files
authored
Fixes #3847 Bug Inconsistent zoom behavior (#4148)
* Fixes inconsistent zoom behaviour * Fixes zoom for multiple blocks * Updating cache for bitmap * Added some debounce delay * Update refreshCanvas to force redraw
1 parent 369c46e commit 29ef513

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

js/activity.js

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,18 +1592,20 @@ class Activity {
15921592
if (this.blockscale < BLOCKSCALES.length - 1) {
15931593
this.resizeDebounce = true;
15941594
this.blockscale += 1;
1595+
this.clearCache();
15951596
await this.blocks.setBlockScale(BLOCKSCALES[this.blockscale]);
1597+
this.blocks.checkBounds();
1598+
this.refreshCanvas();
15961599
}
15971600

15981601
const that = this;
1599-
that.resizeDebounce = false;
1600-
await this.setSmallerLargerStatus();
1601-
1602+
setTimeout(() => {
1603+
that.resizeDebounce = false;
1604+
}, 200);
16021605
}
1603-
if (typeof(this.activity)!="undefined"){
1604-
await this.activity.refreshCanvas();
1605-
}
1606-
document.getElementById("hideContents").click();
1606+
1607+
await this.setSmallerLargerStatus();
1608+
await this.stage.update();
16071609
};
16081610

16091611
/**
@@ -1629,19 +1631,21 @@ class Activity {
16291631
if (this.blockscale > 0) {
16301632
this.resizeDebounce = true;
16311633
this.blockscale -= 1;
1634+
this.clearCache();
16321635
await this.blocks.setBlockScale(BLOCKSCALES[this.blockscale]);
1636+
this.blocks.checkBounds();
1637+
this.refreshCanvas();
16331638
}
16341639

16351640
const that = this;
1636-
that.resizeDebounce = false;
1641+
setTimeout(() => {
1642+
that.resizeDebounce = false;
1643+
}, 200);
16371644

16381645
}
16391646

16401647
await this.setSmallerLargerStatus();
1641-
if (typeof(this.activity)!="undefined"){
1642-
await this.activity.refreshCanvas();
1643-
}
1644-
document.getElementById("hideContents").click();
1648+
await this.stage.update();
16451649
};
16461650

16471651
/*
@@ -3643,6 +3647,22 @@ class Activity {
36433647
// TODO: plugin support
36443648
};
36453649

3650+
/*
3651+
* Clears cache for all blocks
3652+
*/
3653+
this.clearCache = () => {
3654+
this.blocks.blockList.forEach(block => {
3655+
if (block.container) {
3656+
block.container.uncache();
3657+
block.container.cache();
3658+
}
3659+
if (block.bitmap) {
3660+
block.bitmap.uncache();
3661+
block.bitmap.cache();
3662+
}
3663+
});
3664+
};
3665+
36463666
/*
36473667
* Updates all canvas elements
36483668
*/
@@ -3651,15 +3671,17 @@ class Activity {
36513671
return;
36523672
}
36533673

3654-
this.blockRefreshCanvas = true;
3655-
3674+
this.blockRefreshCanvas = true;
3675+
// Force stage clear and update
3676+
this.stage.clear();
3677+
this.stage.update();
3678+
this.update = true;
3679+
36563680
const that = this;
36573681
setTimeout(() => {
36583682
that.blockRefreshCanvas = false;
3683+
that.stage.update();
36593684
}, 5);
3660-
3661-
this.stage.update(event);
3662-
this.update = true;
36633685
};
36643686

36653687
/*

0 commit comments

Comments
 (0)