[Editor] Shift the signature editor when pasted
The idea is to avoid to have the pasted editor hidding the copied one: the user could think that nothing happened. So the top-left corner of the pasted one is moved to the bottom-right corner of the copied one.
This commit is contained in:
parent
878d206c79
commit
cc3d6ab539
@ -628,6 +628,12 @@ class DrawingEditor extends AnnotationEditor {
|
|||||||
return this.div;
|
return this.div;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let baseX, baseY;
|
||||||
|
if (this._isCopy) {
|
||||||
|
baseX = this.x;
|
||||||
|
baseY = this.y;
|
||||||
|
}
|
||||||
|
|
||||||
const div = super.render();
|
const div = super.render();
|
||||||
div.classList.add("draw");
|
div.classList.add("draw");
|
||||||
|
|
||||||
@ -640,6 +646,10 @@ class DrawingEditor extends AnnotationEditor {
|
|||||||
this._uiManager.addShouldRescale(this);
|
this._uiManager.addShouldRescale(this);
|
||||||
this.disableEditing();
|
this.disableEditing();
|
||||||
|
|
||||||
|
if (this._isCopy) {
|
||||||
|
this._moveAfterPaste(baseX, baseY);
|
||||||
|
}
|
||||||
|
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,6 +85,8 @@ class AnnotationEditor {
|
|||||||
|
|
||||||
#touchManager = null;
|
#touchManager = null;
|
||||||
|
|
||||||
|
_isCopy = false;
|
||||||
|
|
||||||
_editToolbar = null;
|
_editToolbar = null;
|
||||||
|
|
||||||
_initialOptions = Object.create(null);
|
_initialOptions = Object.create(null);
|
||||||
@ -442,6 +444,17 @@ class AnnotationEditor {
|
|||||||
this.fixAndSetPosition();
|
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) {
|
#translate([width, height], x, y) {
|
||||||
[x, y] = this.screenToPageTranslation(x, y);
|
[x, y] = this.screenToPageTranslation(x, y);
|
||||||
|
|
||||||
@ -1597,6 +1610,7 @@ class AnnotationEditor {
|
|||||||
});
|
});
|
||||||
editor.rotation = data.rotation;
|
editor.rotation = data.rotation;
|
||||||
editor.#accessibilityData = data.accessibilityData;
|
editor.#accessibilityData = data.accessibilityData;
|
||||||
|
editor._isCopy = data.isCopy || false;
|
||||||
|
|
||||||
const [pageWidth, pageHeight] = editor.pageDimensions;
|
const [pageWidth, pageHeight] = editor.pageDimensions;
|
||||||
const [x, y, width, height] = editor.getRectInCurrentCoords(
|
const [x, y, width, height] = editor.getRectInCurrentCoords(
|
||||||
|
|||||||
@ -553,7 +553,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let baseX, baseY;
|
let baseX, baseY;
|
||||||
if (this.width) {
|
if (this._isCopy || this.annotationElementId) {
|
||||||
baseX = this.x;
|
baseX = this.x;
|
||||||
baseY = this.y;
|
baseY = this.y;
|
||||||
}
|
}
|
||||||
@ -581,7 +581,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
bindEvents(this, this.div, ["dblclick", "keydown"]);
|
bindEvents(this, this.div, ["dblclick", "keydown"]);
|
||||||
|
|
||||||
if (this.width) {
|
if (this._isCopy || this.annotationElementId) {
|
||||||
// This editor was created in using copy (ctrl+c).
|
// This editor was created in using copy (ctrl+c).
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
const [parentWidth, parentHeight] = this.parentDimensions;
|
||||||
if (this.annotationElementId) {
|
if (this.annotationElementId) {
|
||||||
@ -627,12 +627,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
this.setAt(posX * parentWidth, posY * parentHeight, tx, ty);
|
this.setAt(posX * parentWidth, posY * parentHeight, tx, ty);
|
||||||
} else {
|
} else {
|
||||||
this.setAt(
|
this._moveAfterPaste(baseX, baseY);
|
||||||
baseX * parentWidth,
|
|
||||||
baseY * parentHeight,
|
|
||||||
this.width * parentWidth,
|
|
||||||
this.height * parentHeight
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#setContent();
|
this.#setContent();
|
||||||
@ -847,6 +842,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
if (isForCopying) {
|
if (isForCopying) {
|
||||||
// Don't add the id when copying because the pasted editor mustn't be
|
// Don't add the id when copying because the pasted editor mustn't be
|
||||||
// linked to an existing annotation.
|
// linked to an existing annotation.
|
||||||
|
serialized.isCopy = true;
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -246,6 +246,7 @@ class InkEditor extends DrawingEditor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isForCopying) {
|
if (isForCopying) {
|
||||||
|
serialized.isCopy = true;
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -130,6 +130,15 @@ class SignatureEditor extends DrawingEditor {
|
|||||||
return this.div;
|
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();
|
super.render();
|
||||||
this.div.setAttribute("role", "figure");
|
this.div.setAttribute("role", "figure");
|
||||||
|
|
||||||
@ -163,6 +172,11 @@ class SignatureEditor extends DrawingEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_isCopy) {
|
||||||
|
this._isCopy = true;
|
||||||
|
this._moveAfterPaste(baseX, baseY);
|
||||||
|
}
|
||||||
|
|
||||||
return this.div;
|
return this.div;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,6 +362,7 @@ class SignatureEditor extends DrawingEditor {
|
|||||||
if (isForCopying) {
|
if (isForCopying) {
|
||||||
serialized.paths = { lines, points };
|
serialized.paths = { lines, points };
|
||||||
serialized.uuid = this.#signatureUUID;
|
serialized.uuid = this.#signatureUUID;
|
||||||
|
serialized.isCopy = true;
|
||||||
} else {
|
} else {
|
||||||
serialized.lines = lines;
|
serialized.lines = lines;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -346,7 +346,7 @@ class StampEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let baseX, baseY;
|
let baseX, baseY;
|
||||||
if (this.width) {
|
if (this._isCopy) {
|
||||||
baseX = this.x;
|
baseX = this.x;
|
||||||
baseY = this.y;
|
baseY = this.y;
|
||||||
}
|
}
|
||||||
@ -365,15 +365,8 @@ class StampEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.width && !this.annotationElementId) {
|
if (this._isCopy) {
|
||||||
// This editor was created in using copy (ctrl+c).
|
this._moveAfterPaste(baseX, baseY);
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
|
||||||
this.setAt(
|
|
||||||
baseX * parentWidth,
|
|
||||||
baseY * parentHeight,
|
|
||||||
this.width * parentWidth,
|
|
||||||
this.height * parentHeight
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._uiManager.addShouldRescale(this);
|
this._uiManager.addShouldRescale(this);
|
||||||
@ -854,6 +847,7 @@ class StampEditor extends AnnotationEditor {
|
|||||||
// hence we serialize the bitmap to a data url.
|
// hence we serialize the bitmap to a data url.
|
||||||
serialized.bitmapUrl = this.#serializeBitmap(/* toUrl = */ true);
|
serialized.bitmapUrl = this.#serializeBitmap(/* toUrl = */ true);
|
||||||
serialized.accessibilityData = this.serializeAltText(true);
|
serialized.accessibilityData = this.serializeAltText(true);
|
||||||
|
serialized.isCopy = true;
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -348,13 +348,7 @@ describe("Signature Editor", () => {
|
|||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
await page.waitForSelector(editorSelector, { visible: true });
|
await page.waitForSelector(editorSelector, { visible: true });
|
||||||
await page.waitForSelector(
|
const originalRect = await getRect(page, editorSelector);
|
||||||
`.canvasWrapper > svg use[href="#path_p1_0"]`,
|
|
||||||
{ visible: true }
|
|
||||||
);
|
|
||||||
const originalPath = await page.$eval("#path_p1_0", el =>
|
|
||||||
el.getAttribute("d")
|
|
||||||
);
|
|
||||||
const originalDescription = await page.$eval(
|
const originalDescription = await page.$eval(
|
||||||
`${editorSelector} .altText.editDescription`,
|
`${editorSelector} .altText.editDescription`,
|
||||||
el => el.title
|
el => el.title
|
||||||
@ -365,21 +359,15 @@ describe("Signature Editor", () => {
|
|||||||
|
|
||||||
const pastedEditorSelector = getEditorSelector(1);
|
const pastedEditorSelector = getEditorSelector(1);
|
||||||
await page.waitForSelector(pastedEditorSelector, { visible: true });
|
await page.waitForSelector(pastedEditorSelector, { visible: true });
|
||||||
await page.waitForSelector(
|
const pastedRect = await getRect(page, pastedEditorSelector);
|
||||||
`.canvasWrapper > svg use[href="#path_p1_1"]`,
|
|
||||||
{ visible: true }
|
|
||||||
);
|
|
||||||
const pastedPath = await page.$eval("#path_p1_1", el =>
|
|
||||||
el.getAttribute("d")
|
|
||||||
);
|
|
||||||
const pastedDescription = await page.$eval(
|
const pastedDescription = await page.$eval(
|
||||||
`${pastedEditorSelector} .altText.editDescription`,
|
`${pastedEditorSelector} .altText.editDescription`,
|
||||||
el => el.title
|
el => el.title
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(pastedPath)
|
expect(pastedRect)
|
||||||
.withContext(`In ${browserName}`)
|
.withContext(`In ${browserName}`)
|
||||||
.toEqual(originalPath);
|
.not.toEqual(originalRect);
|
||||||
expect(pastedDescription)
|
expect(pastedDescription)
|
||||||
.withContext(`In ${browserName}`)
|
.withContext(`In ${browserName}`)
|
||||||
.toEqual(originalDescription);
|
.toEqual(originalDescription);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user