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