1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #18800 from calixteman/popup_deletion

[Editor] When deleting an annotation with popup, then delete the popup too
This commit is contained in:
calixteman 2024-09-26 18:04:24 +02:00 committed by GitHub
commit c46ac3f73f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 104 additions and 25 deletions

View file

@ -284,6 +284,12 @@ class Page {
}
if (annotation.deleted) {
deletedAnnotations.put(ref, ref);
if (annotation.popupRef) {
const popupRef = Ref.fromString(annotation.popupRef);
if (popupRef) {
deletedAnnotations.put(popupRef, popupRef);
}
}
continue;
}
existingAnnotations?.put(ref);

View file

@ -80,6 +80,8 @@ class AnnotationEditor {
_initialOptions = Object.create(null);
_initialData = null;
_isVisible = true;
_uiManager = null;
@ -1335,6 +1337,19 @@ class AnnotationEditor {
*/
rotate(_angle) {}
/**
* Serialize the editor when it has been deleted.
* @returns {Object}
*/
serializeDeleted() {
return {
id: this.annotationElementId,
deleted: true,
pageIndex: this.pageIndex,
popupRef: this._initialData?.popupRef || "",
};
}
/**
* Serialize the editor.
* The result of the serialization will be used to construct a
@ -1809,11 +1824,7 @@ class FakeEditor extends AnnotationEditor {
}
serialize() {
return {
id: this.annotationElementId,
deleted: true,
pageIndex: this.pageIndex,
};
return this.serializeDeleted();
}
}

View file

@ -48,8 +48,6 @@ class FreeTextEditor extends AnnotationEditor {
#fontSize;
#initialData = null;
static _freeTextDefaultContent = "";
static _internalPadding = 0;
@ -598,7 +596,7 @@ class FreeTextEditor extends AnnotationEditor {
// position is the position of the first glyph in the annotation
// and it's relative to its container.
const { position } = this.#initialData;
const { position } = this._initialData;
let [tx, ty] = this.getInitialTranslation();
[tx, ty] = this.pageTranslationToScreen(tx, ty);
const [pageWidth, pageHeight] = this.pageDimensions;
@ -781,6 +779,7 @@ class FreeTextEditor extends AnnotationEditor {
rect,
rotation,
id,
popupRef,
},
textContent,
textPosition,
@ -805,6 +804,7 @@ class FreeTextEditor extends AnnotationEditor {
rotation,
id,
deleted: false,
popupRef,
};
}
const editor = super.deserialize(data, parent, uiManager);
@ -812,7 +812,7 @@ class FreeTextEditor extends AnnotationEditor {
editor.#color = Util.makeHexColor(...data.color);
editor.#content = FreeTextEditor.#deserializeContent(data.value);
editor.annotationElementId = data.id || null;
editor.#initialData = initialData;
editor._initialData = initialData;
return editor;
}
@ -824,11 +824,7 @@ class FreeTextEditor extends AnnotationEditor {
}
if (this.deleted) {
return {
pageIndex: this.pageIndex,
id: this.annotationElementId,
deleted: true,
};
return this.serializeDeleted();
}
const padding = FreeTextEditor._internalPadding * this.parentScale;
@ -866,7 +862,7 @@ class FreeTextEditor extends AnnotationEditor {
}
#hasElementChanged(serialized) {
const { value, fontSize, color, pageIndex } = this.#initialData;
const { value, fontSize, color, pageIndex } = this._initialData;
return (
this._hasBeenMoved ||

View file

@ -55,8 +55,6 @@ class HighlightEditor extends AnnotationEditor {
#id = null;
#initialData = null;
#isFreeHighlight = false;
#lastPoint = null;
@ -785,7 +783,7 @@ class HighlightEditor extends AnnotationEditor {
let initialData = null;
if (data instanceof HighlightAnnotationElement) {
const {
data: { quadPoints, rect, rotation, id, color, opacity },
data: { quadPoints, rect, rotation, id, color, opacity, popupRef },
parent: {
page: { pageNumber },
},
@ -801,6 +799,7 @@ class HighlightEditor extends AnnotationEditor {
rotation,
id,
deleted: false,
popupRef,
};
} else if (data instanceof InkAnnotationElement) {
const {
@ -811,6 +810,7 @@ class HighlightEditor extends AnnotationEditor {
id,
color,
borderStyle: { rawWidth: thickness },
popupRef,
},
parent: {
page: { pageNumber },
@ -827,6 +827,7 @@ class HighlightEditor extends AnnotationEditor {
rotation,
id,
deleted: false,
popupRef,
};
}
@ -839,7 +840,7 @@ class HighlightEditor extends AnnotationEditor {
editor.#thickness = data.thickness;
}
editor.annotationElementId = data.id || null;
editor.#initialData = initialData;
editor._initialData = initialData;
const [pageWidth, pageHeight] = editor.pageDimensions;
const [pageX, pageY] = editor.pageTranslation;
@ -902,11 +903,7 @@ class HighlightEditor extends AnnotationEditor {
}
if (this.deleted) {
return {
pageIndex: this.pageIndex,
id: this.annotationElementId,
deleted: true,
};
return this.serializeDeleted();
}
const rect = this.getRect(0, 0);
@ -934,7 +931,7 @@ class HighlightEditor extends AnnotationEditor {
}
#hasElementChanged(serialized) {
const { color } = this.#initialData;
const { color } = this._initialData;
return serialized.color.some((c, i) => c !== color[i]);
}