Skip to content

Commit d10bcbf

Browse files
authored
text-tool.js -- fix aligned text edit position
1 parent 8b3a4ac commit d10bcbf

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/helper/tools/text-tool.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,26 @@ class TextTool extends paper.Tool {
176176
const textBoxMtx = this.textBox.matrix;
177177
const calculated = new paper.Matrix();
178178

179-
// In RTL, the element is moved relative to its parent's right edge instead of its left
180-
// edge. We need to correct for this in order for the element to overlap the object in paper.
181-
let tx = 0;
182-
if ((this.alignment === "right") && this.element.parentElement) {
183-
if (window.test) tx = window.test({}, this, textBoxMtx, viewMtx);
184-
else tx = -this.element.parentElement.clientWidth;
185-
}
186-
if ((this.alignment === "center") && this.element.parentElement) {
187-
const bounds = this.textBox.getBounds();
188-
if (window.test) tx = window.test(bounds, this, textBoxMtx, viewMtx);
189-
else tx = bounds.x / (1 + paper.view.zoom * 0.5);
190-
}
191179
// The transform origin in paper is x at justification side, y at the baseline of the text.
192180
// The offset from (0, 0) to the upper left corner is recorded by internalBounds
193181
// (so this.textBox.internalBounds.y is negative).
194182
// Move the transform origin down to the text baseline to match paper
195183
this.element.style.transformOrigin = `${-this.textBox.internalBounds.x}px ${-this.textBox.internalBounds.y}px`;
196-
if (window.test2) window.test2();
184+
this.element.style.textAlign = "left";
185+
186+
// In RTL, the element is moved relative to its parent's right edge instead of its left
187+
// edge. We need to correct for this in order for the element to overlap the object in paper.
188+
let tx = 0;
189+
if (this.element.parentElement) {
190+
tx = this.textBox.internalBounds.x;
191+
if (this.alignment === "right") {
192+
this.element.style.textAlign = "right";
193+
} else if (this.alignment === "center") {
194+
this.element.style.textAlign = "center";
195+
this.element.style.transformOrigin = `center ${-this.textBox.internalBounds.y}px`;
196+
}
197+
}
198+
197199
// Start by translating the element up so that its (0, 0) is now at the text baseline, like in paper
198200
calculated.translate(tx, this.textBox.internalBounds.y);
199201
calculated.append(viewMtx);

0 commit comments

Comments
 (0)