[Editor] When clicking on a comment in the sidebar, wait for the annotation editor layer to be rendered

and add a getter for the layer bounding rect.
This commit is contained in:
Calixte Denizet 2025-09-08 17:13:07 +02:00
parent d946de904c
commit 54351ee437
3 changed files with 15 additions and 6 deletions

View File

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

View File

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

View File

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