Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.

Commit a38a373

Browse files
author
Aaron Imming
committed
Resize workspace svg on workspace event
1 parent af9348a commit a38a373

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/scratch/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ export const scratchWorkspaceInit = async (scratch_area_name, scratch_div_name)
4444

4545
const onWorkspaceResize = () => {
4646
let el_scratch_area = document.getElementById(scratch_area_name);
47-
4847
const scratch_area = el_scratch_area;
49-
const scratch_div = document.getElementById(scratch_div_name);
48+
const el_scratch_div = document.getElementById(scratch_div_name);
5049

5150
let x = 0;
5251
let y = 0;
@@ -58,14 +57,17 @@ export const scratchWorkspaceInit = async (scratch_area_name, scratch_div_name)
5857
} while (el_scratch_area);
5958

6059
// Position scratch_div over scratch_area.
61-
scratch_div.style.left = `${x}px`;
62-
scratch_div.style.top = `${y}px`;
63-
scratch_div.style.width = `${scratch_area.offsetWidth}px`;
64-
scratch_div.style.height = `${scratch_area.offsetHeight}px`;
60+
el_scratch_div.style.left = `${x}px`;
61+
el_scratch_div.style.top = `${y}px`;
62+
el_scratch_div.style.width = `${scratch_area.offsetWidth}px`;
63+
el_scratch_div.style.height = `${scratch_area.offsetHeight}px`;
6564

6665
Blockly.svgResize(workspace);
6766
};
6867

68+
// Resize workspace on workspace event, workaround for jumping workspace.
69+
workspace.addChangeListener(() => Blockly.svgResize(workspace));
70+
6971
window.addEventListener('resize', onWorkspaceResize);
7072
onWorkspaceResize();
7173
} catch (error) {

0 commit comments

Comments
 (0)