Skip to content

Commit 96972a4

Browse files
committed
fix: Fix positioning of pasted blocks in RTL.
1 parent d7efb28 commit 96972a4

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

core/clipboard/block_paster.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export function moveBlockToNotConflict(
8383
block: BlockSvg,
8484
originalPosition: Coordinate,
8585
) {
86+
if (block.workspace.RTL) {
87+
originalPosition.x = block.workspace.getWidth() - originalPosition.x;
88+
}
8689
const workspace = block.workspace;
8790
const snapRadius = config.snapRadius;
8891
const bumpOffset = Coordinate.difference(

tests/mocha/clipboard_test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,30 @@ suite('Clipboard', function () {
157157
);
158158
});
159159

160+
test('pasted blocks are bumped to not overlap in RTL', function () {
161+
this.workspace.dispose();
162+
this.workspace = Blockly.inject('blocklyDiv', {rtl: true});
163+
const block = Blockly.serialization.blocks.append(
164+
{
165+
'type': 'controls_if',
166+
'x': 38,
167+
'y': 13,
168+
},
169+
this.workspace,
170+
);
171+
const data = block.toCopyData();
172+
173+
const newBlock = Blockly.clipboard.paste(data, this.workspace);
174+
const oldBlockXY = block.getRelativeToSurfaceXY();
175+
assert.deepEqual(
176+
newBlock.getRelativeToSurfaceXY(),
177+
new Blockly.utils.Coordinate(
178+
oldBlockXY.x - Blockly.config.snapRadius,
179+
oldBlockXY.y + Blockly.config.snapRadius * 2,
180+
),
181+
);
182+
});
183+
160184
test('pasted blocks are bumped to be outside the connection snap radius', function () {
161185
Blockly.serialization.workspaces.load(
162186
{

0 commit comments

Comments
 (0)