Skip to content

Commit

Permalink
Merge pull request #17031 from calixteman/bug1854991
Browse files Browse the repository at this point in the history
[Editor] Slightly postpone the move in the DOM in order to not block the UI (bug 1854991)
  • Loading branch information
calixteman authored Sep 25, 2023
2 parents 57d196e + 29bc103 commit 549c414
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class AnnotationEditor {

#isInEditMode = false;

#moveInDOMTimeout = null;

_initialOptions = Object.create(null);

_uiManager = null;
Expand Down Expand Up @@ -1046,7 +1048,16 @@ class AnnotationEditor {
}

moveInDOM() {
this.parent?.moveEditorInDOM(this);
// Moving the editor in the DOM can be expensive, so we wait a bit before.
// It's important to not block the UI (for example when changing the font
// size in a FreeText).
if (this.#moveInDOMTimeout) {
clearTimeout(this.#moveInDOMTimeout);
}
this.#moveInDOMTimeout = setTimeout(() => {
this.#moveInDOMTimeout = null;
this.parent?.moveEditorInDOM(this);
}, 0);
}

_setParentAndPosition(parent, x, y) {
Expand Down Expand Up @@ -1253,6 +1264,10 @@ class AnnotationEditor {
this.#altTextButton?.remove();
this.#altTextButton = null;
this.#altTextTooltip = null;
if (this.#moveInDOMTimeout) {
clearTimeout(this.#moveInDOMTimeout);
this.#moveInDOMTimeout = null;
}
}

/**
Expand Down

0 comments on commit 549c414

Please sign in to comment.