Skip to content

Commit

Permalink
fix: comment positioning with XML
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Mar 18, 2024
1 parent c35ac57 commit d09cbe2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ function saveWorkspaceComment(
const elem = utilsXml.createElement('comment');
if (saveId) elem.setAttribute('id', comment.id);

elem.setAttribute('x', `${comment.getRelativeToSurfaceXY().x}`);
elem.setAttribute('y', `${comment.getRelativeToSurfaceXY().y}`);
const workspace = comment.workspace;
const loc = comment.getRelativeToSurfaceXY();
loc.x = workspace.RTL ? workspace.getWidth() - loc.x : loc.x;
elem.setAttribute('x', `${loc.x}`);
elem.setAttribute('y', `${loc.y}`);
elem.setAttribute('w', `${comment.getSize().width}`);
elem.setAttribute('h', `${comment.getSize().height}`);

Expand Down Expand Up @@ -503,9 +506,12 @@ function loadWorkspaceComment(

comment.setText(elem.textContent ?? '');

const x = parseInt(elem.getAttribute('x') ?? '', 10);
let x = parseInt(elem.getAttribute('x') ?? '', 10);
const y = parseInt(elem.getAttribute('y') ?? '', 10);
if (!isNaN(x) && !isNaN(y)) comment.moveTo(new Coordinate(x, y));
if (!isNaN(x) && !isNaN(y)) {
x = workspace.RTL ? workspace.getWidth() - x : x;
comment.moveTo(new Coordinate(x, y));
}

const w = parseInt(elem.getAttribute('w') ?? '', 10);
const h = parseInt(elem.getAttribute('h') ?? '', 10);
Expand Down

0 comments on commit d09cbe2

Please sign in to comment.