Skip to content

Commit

Permalink
Merge pull request #15970 from calixteman/editor_invisible
Browse files Browse the repository at this point in the history
[Editor] Make the annotation editor layer invisible when disabled and empty
  • Loading branch information
calixteman authored Feb 1, 2023
2 parents 2d87a2e + 1852819 commit 1bdee0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class AnnotationEditorLayer {
this.#uiManager.addLayer(this);
}

get isEmpty() {
return this.#editors.size === 0;
}

/**
* Update the toolbar if it's required to reflect the tool currently used.
* @param {number} mode
Expand All @@ -107,11 +111,17 @@ class AnnotationEditorLayer {
}
this.#uiManager.unselectAll();

this.div.classList.toggle(
"freeTextEditing",
mode === AnnotationEditorType.FREETEXT
);
this.div.classList.toggle("inkEditing", mode === AnnotationEditorType.INK);
if (mode !== AnnotationEditorType.NONE) {
this.div.classList.toggle(
"freeTextEditing",
mode === AnnotationEditorType.FREETEXT
);
this.div.classList.toggle(
"inkEditing",
mode === AnnotationEditorType.INK
);
this.div.hidden = false;
}
}

addInkEditorIfNeeded(isCommitting) {
Expand Down Expand Up @@ -172,6 +182,10 @@ class AnnotationEditorLayer {
for (const editor of this.#editors.values()) {
editor.disableEditing();
}
this.#cleanup();
if (this.isEmpty) {
this.div.hidden = true;
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion web/annotation_editor_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class AnnotationEditorLayerBuilder {
const div = (this.div = document.createElement("div"));
div.className = "annotationEditorLayer";
div.tabIndex = 0;
div.hidden = true;
this.pageDiv.append(div);

this.annotationEditorLayer = new AnnotationEditorLayer({
Expand All @@ -94,6 +95,7 @@ class AnnotationEditorLayerBuilder {
};

this.annotationEditorLayer.render(parameters);
this.show();
}

cancel() {
Expand All @@ -115,7 +117,7 @@ class AnnotationEditorLayerBuilder {
}

show() {
if (!this.div) {
if (!this.div || this.annotationEditorLayer.isEmpty) {
return;
}
this.div.hidden = false;
Expand Down

0 comments on commit 1bdee0b

Please sign in to comment.