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

Merge pull request #19144 from calixteman/no_focus_if_invisible

[Editor] Don't focus a newly added drawing if it isn't visible on screen
This commit is contained in:
calixteman 2024-12-02 14:02:01 +01:00 committed by GitHub
commit 97c7a8eb7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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;