Skip to content

Commit

Permalink
Merge pull request #19202 from calixteman/avoid_to_lose_focus
Browse files Browse the repository at this point in the history
[Editor] Don't commit the current drawing while zooming
  • Loading branch information
calixteman authored Dec 9, 2024
2 parents 438c641 + 166a529 commit 898be9e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class AnnotationEditorLayer {

#drawingAC = null;

#focusedElement = null;

#textLayer = null;

#textSelectionAC = null;
Expand Down Expand Up @@ -811,6 +813,7 @@ class AnnotationEditorLayer {
"blur",
({ relatedTarget }) => {
if (relatedTarget && !this.div.contains(relatedTarget)) {
this.#focusedElement = null;
this.commitOrRemove();
}
},
Expand All @@ -819,13 +822,30 @@ class AnnotationEditorLayer {
this.#currentEditorType.startDrawing(this, this.#uiManager, false, event);
}

pause(on) {
if (on) {
const { activeElement } = document;
if (this.div.contains(activeElement)) {
this.#focusedElement = activeElement;
}
return;
}
if (this.#focusedElement) {
setTimeout(() => {
this.#focusedElement?.focus();
this.#focusedElement = null;
}, 0);
}
}

endDrawingSession(isAborted = false) {
if (!this.#drawingAC) {
return null;
}
this.#uiManager.setCurrentDrawingSession(null);
this.#drawingAC.abort();
this.#drawingAC = null;
this.#focusedElement = null;
return this.#currentEditorType.endDrawing(isAborted);
}

Expand Down
2 changes: 2 additions & 0 deletions web/annotation_editor_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class AnnotationEditorLayerBuilder {
if (!this.div) {
return;
}
this.annotationEditorLayer.pause(/* on */ true);
this.div.hidden = true;
}

Expand All @@ -148,6 +149,7 @@ class AnnotationEditorLayerBuilder {
return;
}
this.div.hidden = false;
this.annotationEditorLayer.pause(/* on */ false);
}
}

Expand Down

0 comments on commit 898be9e

Please sign in to comment.