Skip to content

Commit

Permalink
[Editor] Remove almost all the waitForTimeout from the freetext integ…
Browse files Browse the repository at this point in the history
…ration tests
  • Loading branch information
calixteman committed Sep 27, 2023
1 parent 3f7060e commit f19b48e
Show file tree
Hide file tree
Showing 4 changed files with 627 additions and 336 deletions.
26 changes: 24 additions & 2 deletions src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ class AnnotationEditorLayer {

#editors = new Map();

#focusContainerTimeout = null;

#hadPointerDown = false;

#moveInDOMTimeout = null;

#isCleaningUp = false;

#isDisabling = false;
Expand Down Expand Up @@ -330,7 +334,11 @@ class AnnotationEditorLayer {
this.detach(editor);
this.#uiManager.removeEditor(editor);
if (editor.div.contains(document.activeElement)) {
setTimeout(() => {
if (this.#focusContainerTimeout) {
clearTimeout(this.#focusContainerTimeout);
}
this.#focusContainerTimeout = setTimeout(() => {
this.#focusContainerTimeout = null;
// When the div is removed from DOM the focus can move on the
// document.body, so we need to move it back to the main container.
this.#uiManager.focusMainContainer();
Expand Down Expand Up @@ -402,7 +410,11 @@ class AnnotationEditorLayer {
// don't want to call any focus callbacks, hence we disable them and only
// re-enable them when the editor has the focus.
editor._focusEventsAllowed = false;
setTimeout(() => {
if (this.#moveInDOMTimeout) {
clearTimeout(this.#moveInDOMTimeout);
}
this.#moveInDOMTimeout = setTimeout(() => {
this.#moveInDOMTimeout = null;
if (!editor.div.contains(document.activeElement)) {
editor.div.addEventListener(
"focusin",
Expand Down Expand Up @@ -683,6 +695,16 @@ class AnnotationEditorLayer {
this.#uiManager.setActiveEditor(null);
}

if (this.#moveInDOMTimeout) {
clearTimeout(this.#moveInDOMTimeout);
this.#moveInDOMTimeout = null;
}

if (this.#focusContainerTimeout) {
clearTimeout(this.#focusContainerTimeout);
this.#focusContainerTimeout = null;
}

for (const editor of this.#editors.values()) {
this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
editor.setParent(null);
Expand Down
Loading

0 comments on commit f19b48e

Please sign in to comment.