Skip to content

Commit

Permalink
fix: improve positioning of newly created procedure blocks (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfunko authored Aug 13, 2024
1 parent 46854cd commit 84a9e5b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,18 +290,20 @@ function createProcedureCallbackFactory_(workspace) {
var blockDom = Blockly.utils.xml.textToDom(blockText).firstChild;
Blockly.Events.setGroup(true);
var block = Blockly.Xml.domToBlock(blockDom, workspace);
var scale = workspace.scale; // To convert from pixel units to workspace units
// Position the block so that it is at the top left of the visible workspace,
// padded from the edge by 30 units. Position in the top right if RTL.
var posX = -workspace.scrollX;
if (workspace.RTL) {
posX += workspace.getMetrics().contentWidth - 30;
} else {
posX += 30;
}
block.moveBy(posX / scale, (-workspace.scrollY + 30) / scale);
block.scheduleSnapAndBump();
Blockly.Events.setGroup(false);
Blockly.renderManagement.finishQueuedRenders().then(() => {
var scale = workspace.scale; // To convert from pixel units to workspace units
// Position the block so that it is at the top left of the visible workspace,
// padded from the edge by 30 units. Position in the top right if RTL.
var posX = -workspace.scrollX;
if (workspace.RTL) {
posX += workspace.getMetrics().contentWidth - 30;
} else {
posX += 30;
}
block.moveBy(posX / scale, (-workspace.scrollY + 30) / scale);
block.scheduleSnapAndBump();
Blockly.Events.setGroup(false);
});
}
};
}
Expand Down

0 comments on commit 84a9e5b

Please # to comment.