Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Editor] Shift the signature editor when pasted #19539

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/display/editor/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,12 @@ class DrawingEditor extends AnnotationEditor {
return this.div;
}

let baseX, baseY;
if (this._isCopy) {
baseX = this.x;
baseY = this.y;
}

const div = super.render();
div.classList.add("draw");

Expand All @@ -640,6 +646,10 @@ class DrawingEditor extends AnnotationEditor {
this._uiManager.addShouldRescale(this);
this.disableEditing();

if (this._isCopy) {
this._moveAfterPaste(baseX, baseY);
}

return div;
}

Expand Down
14 changes: 14 additions & 0 deletions src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class AnnotationEditor {

#touchManager = null;

_isCopy = false;

_editToolbar = null;

_initialOptions = Object.create(null);
Expand Down Expand Up @@ -442,6 +444,17 @@ class AnnotationEditor {
this.fixAndSetPosition();
}

_moveAfterPaste(baseX, baseY) {
const [parentWidth, parentHeight] = this.parentDimensions;
this.setAt(
baseX * parentWidth,
baseY * parentHeight,
this.width * parentWidth,
this.height * parentHeight
);
this._onTranslated();
}

#translate([width, height], x, y) {
[x, y] = this.screenToPageTranslation(x, y);

Expand Down Expand Up @@ -1597,6 +1610,7 @@ class AnnotationEditor {
});
editor.rotation = data.rotation;
editor.#accessibilityData = data.accessibilityData;
editor._isCopy = data.isCopy || false;

const [pageWidth, pageHeight] = editor.pageDimensions;
const [x, y, width, height] = editor.getRectInCurrentCoords(
Expand Down
12 changes: 4 additions & 8 deletions src/display/editor/freetext.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class FreeTextEditor extends AnnotationEditor {
}

let baseX, baseY;
if (this.width) {
if (this._isCopy || this.annotationElementId) {
baseX = this.x;
baseY = this.y;
}
Expand Down Expand Up @@ -581,7 +581,7 @@ class FreeTextEditor extends AnnotationEditor {

bindEvents(this, this.div, ["dblclick", "keydown"]);

if (this.width) {
if (this._isCopy || this.annotationElementId) {
// This editor was created in using copy (ctrl+c).
const [parentWidth, parentHeight] = this.parentDimensions;
if (this.annotationElementId) {
Expand Down Expand Up @@ -627,12 +627,7 @@ class FreeTextEditor extends AnnotationEditor {
}
this.setAt(posX * parentWidth, posY * parentHeight, tx, ty);
} else {
this.setAt(
baseX * parentWidth,
baseY * parentHeight,
this.width * parentWidth,
this.height * parentHeight
);
this._moveAfterPaste(baseX, baseY);
}

this.#setContent();
Expand Down Expand Up @@ -847,6 +842,7 @@ class FreeTextEditor extends AnnotationEditor {
if (isForCopying) {
// Don't add the id when copying because the pasted editor mustn't be
// linked to an existing annotation.
serialized.isCopy = true;
return serialized;
}

Expand Down
1 change: 1 addition & 0 deletions src/display/editor/ink.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class InkEditor extends DrawingEditor {
};

if (isForCopying) {
serialized.isCopy = true;
return serialized;
}

Expand Down
15 changes: 15 additions & 0 deletions src/display/editor/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ class SignatureEditor extends DrawingEditor {
return this.div;
}

let baseX, baseY;
const { _isCopy } = this;
if (_isCopy) {
// No need to adjust the position when rendering in DrawingEditor.
this._isCopy = false;
baseX = this.x;
baseY = this.y;
}

super.render();
this.div.setAttribute("role", "figure");

Expand Down Expand Up @@ -163,6 +172,11 @@ class SignatureEditor extends DrawingEditor {
}
}

if (_isCopy) {
this._isCopy = true;
this._moveAfterPaste(baseX, baseY);
}

return this.div;
}

Expand Down Expand Up @@ -348,6 +362,7 @@ class SignatureEditor extends DrawingEditor {
if (isForCopying) {
serialized.paths = { lines, points };
serialized.uuid = this.#signatureUUID;
serialized.isCopy = true;
} else {
serialized.lines = lines;
}
Expand Down
14 changes: 4 additions & 10 deletions src/display/editor/stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class StampEditor extends AnnotationEditor {
}

let baseX, baseY;
if (this.width) {
if (this._isCopy) {
baseX = this.x;
baseY = this.y;
}
Expand All @@ -365,15 +365,8 @@ class StampEditor extends AnnotationEditor {
}
}

if (this.width && !this.annotationElementId) {
// This editor was created in using copy (ctrl+c).
const [parentWidth, parentHeight] = this.parentDimensions;
this.setAt(
baseX * parentWidth,
baseY * parentHeight,
this.width * parentWidth,
this.height * parentHeight
);
if (this._isCopy) {
this._moveAfterPaste(baseX, baseY);
}

this._uiManager.addShouldRescale(this);
Expand Down Expand Up @@ -854,6 +847,7 @@ class StampEditor extends AnnotationEditor {
// hence we serialize the bitmap to a data url.
serialized.bitmapUrl = this.#serializeBitmap(/* toUrl = */ true);
serialized.accessibilityData = this.serializeAltText(true);
serialized.isCopy = true;
return serialized;
}

Expand Down
20 changes: 4 additions & 16 deletions test/integration/signature_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,7 @@ describe("Signature Editor", () => {

const editorSelector = getEditorSelector(0);
await page.waitForSelector(editorSelector, { visible: true });
await page.waitForSelector(
`.canvasWrapper > svg use[href="#path_p1_0"]`,
{ visible: true }
);
const originalPath = await page.$eval("#path_p1_0", el =>
el.getAttribute("d")
);
const originalRect = await getRect(page, editorSelector);
const originalDescription = await page.$eval(
`${editorSelector} .altText.editDescription`,
el => el.title
Expand All @@ -365,21 +359,15 @@ describe("Signature Editor", () => {

const pastedEditorSelector = getEditorSelector(1);
await page.waitForSelector(pastedEditorSelector, { visible: true });
await page.waitForSelector(
`.canvasWrapper > svg use[href="#path_p1_1"]`,
{ visible: true }
);
const pastedPath = await page.$eval("#path_p1_1", el =>
el.getAttribute("d")
);
const pastedRect = await getRect(page, pastedEditorSelector);
const pastedDescription = await page.$eval(
`${pastedEditorSelector} .altText.editDescription`,
el => el.title
);

expect(pastedPath)
expect(pastedRect)
.withContext(`In ${browserName}`)
.toEqual(originalPath);
.not.toEqual(originalRect);
expect(pastedDescription)
.withContext(`In ${browserName}`)
.toEqual(originalDescription);
Expand Down