Skip to content

Commit

Permalink
[Editor] Slightly postpone the move in the DOM in order to not block …
Browse files Browse the repository at this point in the history
…the UI (bug 1854991)
  • Loading branch information
calixteman committed Sep 25, 2023
1 parent 57d196e commit 29bc103
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 29bc103

Please sign in to comment.