Merge pull request #20247 from calixteman/wait_for_rendered_editors

[Editor] When clicking on a comment in the sidebar, wait for the annotation editor layer to be rendered
This commit is contained in:
calixteman 2025-09-09 09:26:45 +02:00 committed by GitHub
commit 5b7f9ca8b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 6 deletions

View File

@ -281,6 +281,10 @@ class AnnotationEditorLayer {
editor.enableEditing(); editor.enableEditing();
} }
this.#isEnabling = false; this.#isEnabling = false;
this.#uiManager._eventBus.dispatch("editorsrendered", {
source: this,
pageNumber: this.pageIndex + 1,
});
} }
/** /**
@ -745,8 +749,12 @@ class AnnotationEditorLayer {
return editor; return editor;
} }
get boundingClientRect() {
return this.div.getBoundingClientRect();
}
#getCenterPoint() { #getCenterPoint() {
const { x, y, width, height } = this.div.getBoundingClientRect(); const { x, y, width, height } = this.boundingClientRect;
const tlX = Math.max(0, x); const tlX = Math.max(0, x);
const tlY = Math.max(0, y); const tlY = Math.max(0, y);
const brX = Math.min(window.innerWidth, x + width); const brX = Math.min(window.innerWidth, x + width);

View File

@ -1078,18 +1078,18 @@ class AnnotationEditorUIManager {
editor?.showComment(); editor?.showComment();
} }
async waitForPageRendered(pageNumber) { async waitForEditorsRendered(pageNumber) {
if (this.#allLayers.has(pageNumber - 1)) { if (this.#allLayers.has(pageNumber - 1)) {
return; return;
} }
const { resolve, promise } = Promise.withResolvers(); const { resolve, promise } = Promise.withResolvers();
const onPageRendered = evt => { const onEditorsRendered = evt => {
if (evt.pageNumber === pageNumber) { if (evt.pageNumber === pageNumber) {
this._eventBus._off("annotationeditorlayerrendered", onPageRendered); this._eventBus._off("editorsrendered", onEditorsRendered);
resolve(); resolve();
} }
}; };
this._eventBus.on("annotationeditorlayerrendered", onPageRendered); this._eventBus.on("editorsrendered", onEditorsRendered);
await promise; await promise;
} }

View File

@ -670,7 +670,8 @@ class CommentSidebar {
const { id, pageIndex, rect } = annotation; const { id, pageIndex, rect } = annotation;
const SPACE_ABOVE_ANNOTATION = 10; const SPACE_ABOVE_ANNOTATION = 10;
const pageNumber = pageIndex + 1; const pageNumber = pageIndex + 1;
const pageVisiblePromise = this.#uiManager?.waitForPageRendered(pageNumber); const pageVisiblePromise =
this.#uiManager?.waitForEditorsRendered(pageNumber);
this.#linkService?.goToXY( this.#linkService?.goToXY(
pageNumber, pageNumber,
rect[0], rect[0],