Skip to content

Commit 8c30056

Browse files
authored
Merge pull request #840 from rgantzos/snap-scripts-to-grid
Snap scripts to grid
2 parents 28d3642 + 5176ae8 commit 8c30056

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

features/features.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"version": 2,
4+
"id": "snap-to-grid",
5+
"versionAdded": "v4.0.0"
6+
},
27
{
38
"version": 2,
49
"id": "select-self",

features/snap-to-grid/data.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"title": "Snap Scripts to Grid",
3+
"description": "Automatically aligns scripts to the dotted grid in the editor when placed.",
4+
"credits": [
5+
{
6+
"username": "rgantzos",
7+
"url": "https://scratch.mit.edu/users/rgantzos/"
8+
}
9+
],
10+
"type": [
11+
"Editor"
12+
],
13+
"tags": [
14+
"New"
15+
],
16+
"scripts": [
17+
{
18+
"file": "script.js",
19+
"runOn": "/projects/*"
20+
}
21+
]
22+
}

features/snap-to-grid/script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default async function ({ feature, console }) {
2+
await ScratchTools.waitForElement("div.gui")
3+
update()
4+
5+
feature.traps.vm.on("workspaceUpdate", function() {
6+
update()
7+
})
8+
9+
function update() {
10+
Blockly.getMainWorkspace().grid_.snapToGrid_ = feature.self.enabled
11+
}
12+
}

0 commit comments

Comments
 (0)