Merge pull request #15244 from calixteman/15241
[Editor] Add an editor in the annotation storage only when it's non-empty (#15241)
This commit is contained in:
commit
ee8fab929c
@ -102,6 +102,15 @@ class AnnotationStorage {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the storage contains the given key.
|
||||
* @param {string} key
|
||||
* @returns {boolean}
|
||||
*/
|
||||
has(key) {
|
||||
return this._storage.has(key);
|
||||
}
|
||||
|
||||
getAll() {
|
||||
return this._storage.size > 0 ? objectFromMap(this._storage) : null;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import { InkEditor } from "./ink.js";
|
||||
* @property {HTMLDivElement} div
|
||||
* @property {AnnotationEditorUIManager} uiManager
|
||||
* @property {boolean} enabled
|
||||
* @property {AnnotationStorage} annotationStorag
|
||||
* @property {AnnotationStorage} annotationStorage
|
||||
* @property {number} pageIndex
|
||||
* @property {IL10n} l10n
|
||||
*/
|
||||
@ -426,7 +426,7 @@ class AnnotationEditorLayer {
|
||||
*/
|
||||
add(editor) {
|
||||
this.#changeParent(editor);
|
||||
this.annotationStorage.setValue(editor.id, editor);
|
||||
this.addToAnnotationStorage(editor);
|
||||
this.#uiManager.addEditor(editor);
|
||||
this.attach(editor);
|
||||
|
||||
@ -440,6 +440,16 @@ class AnnotationEditorLayer {
|
||||
editor.onceAdded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an editor in the annotation storage.
|
||||
* @param {AnnotationEditor} editor
|
||||
*/
|
||||
addToAnnotationStorage(editor) {
|
||||
if (!editor.isEmpty() && !this.annotationStorage.has(editor.id)) {
|
||||
this.annotationStorage.setValue(editor.id, editor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or rebuild depending if it has been removed or not.
|
||||
* @param {AnnotationEditor} editor
|
||||
|
@ -136,6 +136,13 @@ class AnnotationEditor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the data contained in this editor.
|
||||
*/
|
||||
commit() {
|
||||
this.parent.addToAnnotationStorage(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* We use drag-and-drop in order to move an editor on a page.
|
||||
* @param {DragEvent} event
|
||||
|
@ -275,7 +275,7 @@ class FreeTextEditor extends AnnotationEditor {
|
||||
|
||||
/** @inheritdoc */
|
||||
isEmpty() {
|
||||
return this.editorDiv.innerText.trim() === "";
|
||||
return !this.editorDiv || this.editorDiv.innerText.trim() === "";
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -320,6 +320,7 @@ class FreeTextEditor extends AnnotationEditor {
|
||||
* @returns {undefined}
|
||||
*/
|
||||
commit() {
|
||||
super.commit();
|
||||
if (!this.#hasAlreadyBeenCommitted) {
|
||||
// This editor has something and it's the first time
|
||||
// it's commited so we can add it in the undo/redo stack.
|
||||
|
@ -469,6 +469,8 @@ class InkEditor extends AnnotationEditor {
|
||||
return;
|
||||
}
|
||||
|
||||
super.commit();
|
||||
|
||||
this.isEditing = false;
|
||||
this.disableEditMode();
|
||||
|
||||
@ -572,6 +574,8 @@ class InkEditor extends AnnotationEditor {
|
||||
"pointermove",
|
||||
this.#boundCanvasPointermove
|
||||
);
|
||||
|
||||
this.parent.addToAnnotationStorage(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user