Skip to content

Commit e355735

Browse files
committed
fix: Fix positioning of pasted comments in RTL.
1 parent c5bb830 commit e355735

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

core/xml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function saveWorkspaceComment(
6868
if (!skipId) elem.setAttribute('id', comment.id);
6969

7070
const workspace = comment.workspace;
71-
const loc = comment.getRelativeToSurfaceXY();
71+
const loc = comment.getRelativeToSurfaceXY().clone();
7272
loc.x = workspace.RTL ? workspace.getWidth() - loc.x : loc.x;
7373
elem.setAttribute('x', `${loc.x}`);
7474
elem.setAttribute('y', `${loc.y}`);

tests/mocha/clipboard_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,28 @@ suite('Clipboard', function () {
236236
new Blockly.utils.Coordinate(40, 40),
237237
);
238238
});
239+
240+
test('pasted comments are bumped to not overlap in RTL', function () {
241+
this.workspace.dispose();
242+
this.workspace = Blockly.inject('blocklyDiv', {rtl: true});
243+
Blockly.Xml.domToWorkspace(
244+
Blockly.utils.xml.textToDom(
245+
'<xml><comment id="test" x=10 y=10/></xml>',
246+
),
247+
this.workspace,
248+
);
249+
const comment = this.workspace.getTopComments(false)[0];
250+
const data = comment.toCopyData();
251+
252+
const newComment = Blockly.clipboard.paste(data, this.workspace);
253+
const oldCommentXY = comment.getRelativeToSurfaceXY();
254+
assert.deepEqual(
255+
newComment.getRelativeToSurfaceXY(),
256+
new Blockly.utils.Coordinate(oldCommentXY.x - 30, oldCommentXY.y + 30),
257+
);
258+
// Restore an LTR workspace.
259+
this.workspace.dispose();
260+
this.workspace = Blockly.inject('blocklyDiv');
261+
});
239262
});
240263
});

0 commit comments

Comments
 (0)