Skip to content

Commit 84a9e5b

Browse files
authored
fix: improve positioning of newly created procedure blocks (#121)
1 parent 46854cd commit 84a9e5b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/procedures.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,20 @@ function createProcedureCallbackFactory_(workspace) {
290290
var blockDom = Blockly.utils.xml.textToDom(blockText).firstChild;
291291
Blockly.Events.setGroup(true);
292292
var block = Blockly.Xml.domToBlock(blockDom, workspace);
293-
var scale = workspace.scale; // To convert from pixel units to workspace units
294-
// Position the block so that it is at the top left of the visible workspace,
295-
// padded from the edge by 30 units. Position in the top right if RTL.
296-
var posX = -workspace.scrollX;
297-
if (workspace.RTL) {
298-
posX += workspace.getMetrics().contentWidth - 30;
299-
} else {
300-
posX += 30;
301-
}
302-
block.moveBy(posX / scale, (-workspace.scrollY + 30) / scale);
303-
block.scheduleSnapAndBump();
304-
Blockly.Events.setGroup(false);
293+
Blockly.renderManagement.finishQueuedRenders().then(() => {
294+
var scale = workspace.scale; // To convert from pixel units to workspace units
295+
// Position the block so that it is at the top left of the visible workspace,
296+
// padded from the edge by 30 units. Position in the top right if RTL.
297+
var posX = -workspace.scrollX;
298+
if (workspace.RTL) {
299+
posX += workspace.getMetrics().contentWidth - 30;
300+
} else {
301+
posX += 30;
302+
}
303+
block.moveBy(posX / scale, (-workspace.scrollY + 30) / scale);
304+
block.scheduleSnapAndBump();
305+
Blockly.Events.setGroup(false);
306+
});
305307
}
306308
};
307309
}

0 commit comments

Comments
 (0)