1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[Editor] Fix undoing an editor deletion (bug 1886959)

The original bug was because the parent was null when trying to show
an highlight annotation which led to an exception.
That led me to think about having some null/non-null parent when removing
an editor: it's a mess especially if a destroyed parent is still attached
to an editor. Consequently, this patch always sets the parent to null when
deleting the editor.
This commit is contained in:
Calixte Denizet 2024-03-22 19:30:56 +01:00
parent b0f54b2235
commit d5a0e557c2
10 changed files with 574 additions and 11 deletions

View file

@ -441,9 +441,6 @@ class AnnotationEditorLayer {
* @param {AnnotationEditor} editor
*/
remove(editor) {
// Since we can undo a removal we need to keep the
// parent property as it is, so don't null it!
this.detach(editor);
this.#uiManager.removeEditor(editor);
editor.div.remove();
@ -546,6 +543,7 @@ class AnnotationEditorLayer {
if (editor.needsToBeRebuilt()) {
editor.parent ||= this;
editor.rebuild();
editor.show();
} else {
this.add(editor);
}
@ -842,6 +840,7 @@ class AnnotationEditorLayer {
setLayerDimensions(this.div, viewport);
for (const editor of this.#uiManager.getEditors(this.pageIndex)) {
this.add(editor);
editor.rebuild();
}
// We're maybe rendering a layer which was invisible when we started to edit
// so we must set the different callbacks for it.

View file

@ -1270,7 +1270,6 @@ class AnnotationEditor {
rebuild() {
this.div?.addEventListener("focusin", this.#boundFocusin);
this.div?.addEventListener("focusout", this.#boundFocusout);
this.show(this._isVisible);
}
/**
@ -1354,6 +1353,7 @@ class AnnotationEditor {
}
this.#telemetryTimeouts = null;
}
this.parent = null;
}
/**
@ -1676,9 +1676,9 @@ class AnnotationEditor {
/**
* Show or hide this editor.
* @param {boolean} visible
* @param {boolean|undefined} visible
*/
show(visible) {
show(visible = this._isVisible) {
this.div.classList.toggle("hidden", !visible);
this._isVisible = visible;
}

View file

@ -418,11 +418,11 @@ class HighlightEditor extends AnnotationEditor {
/** @inheritdoc */
remove() {
super.remove();
this.#cleanDrawLayer();
this._reportTelemetry({
action: "deleted",
});
super.remove();
}
/** @inheritdoc */
@ -628,6 +628,9 @@ class HighlightEditor extends AnnotationEditor {
/** @inheritdoc */
select() {
super.select();
if (!this.#outlineId) {
return;
}
this.parent?.drawLayer.removeClass(this.#outlineId, "hovered");
this.parent?.drawLayer.addClass(this.#outlineId, "selected");
}
@ -635,6 +638,9 @@ class HighlightEditor extends AnnotationEditor {
/** @inheritdoc */
unselect() {
super.unselect();
if (!this.#outlineId) {
return;
}
this.parent?.drawLayer.removeClass(this.#outlineId, "selected");
if (!this.#isFreeHighlight) {
this.#setCaret(/* start = */ false);
@ -646,7 +652,8 @@ class HighlightEditor extends AnnotationEditor {
return !this.#isFreeHighlight;
}
show(visible) {
/** @inheritdoc */
show(visible = this._isVisible) {
super.show(visible);
if (this.parent) {
this.parent.drawLayer.show(this.#id, visible);

View file

@ -471,7 +471,7 @@ class InkEditor extends AnnotationEditor {
this.allRawPaths.push(currentPath);
this.paths.push(bezier);
this.bezierPath2D.push(path2D);
this.rebuild();
this._uiManager.rebuild(this);
};
const undo = () => {

View file

@ -218,7 +218,7 @@ class StampEditor extends AnnotationEditor {
return;
}
if (this.#bitmapId) {
if (this.#bitmapId && this.#canvas === null) {
this.#getBitmap();
}
@ -241,7 +241,8 @@ class StampEditor extends AnnotationEditor {
this.#bitmapPromise ||
this.#bitmap ||
this.#bitmapUrl ||
this.#bitmapFile
this.#bitmapFile ||
this.#bitmapId
);
}

View file

@ -1713,6 +1713,7 @@ class AnnotationEditorUIManager {
layer.addOrRebuild(editor);
} else {
this.addEditor(editor);
this.addToAnnotationStorage(editor);
}
}