1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

[Editor] Don't focus a newly added drawing if it isn't visible on screen

This commit is contained in:
Calixte Denizet 2024-12-02 11:06:13 +01:00
parent d448953166
commit 673c93e832
3 changed files with 66 additions and 1 deletions

View file

@ -344,7 +344,9 @@ class DrawingEditor extends AnnotationEditor {
this.#mustBeCommitted = false;
this.commit();
this.parent.setSelected(this);
this.div.focus();
if (this.isOnScreen) {
this.div.focus();
}
}
}

View file

@ -1402,6 +1402,12 @@ class AnnotationEditor {
return this.div && !this.isAttachedToDOM;
}
get isOnScreen() {
const { top, left, bottom, right } = this.getClientDimensions();
const { innerHeight, innerWidth } = window;
return left < innerWidth && right > 0 && top < innerHeight && bottom > 0;
}
#addFocusListeners() {
if (this.#focusAC || !this.div) {
return;