1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[Editor] Avoid to focus an existing editor when enabling the layer

It fixes #18911.
This commit is contained in:
Calixte Denizet 2024-12-11 13:49:48 +01:00
parent fbac4ab5f3
commit d61b882888
9 changed files with 79 additions and 10 deletions

View file

@ -74,6 +74,8 @@ class AnnotationEditorLayer {
#isDisabling = false;
#isEnabling = false;
#drawingAC = null;
#focusedElement = null;
@ -229,6 +231,7 @@ class AnnotationEditorLayer {
* editor creation.
*/
async enable() {
this.#isEnabling = true;
this.div.tabIndex = 0;
this.togglePointerEvents(true);
const annotationElementIds = new Set();
@ -242,6 +245,7 @@ class AnnotationEditorLayer {
}
if (!this.#annotationLayer) {
this.#isEnabling = false;
return;
}
@ -262,6 +266,7 @@ class AnnotationEditorLayer {
this.addOrRebuild(editor);
editor.enableEditing();
}
this.#isEnabling = false;
}
/**
@ -508,7 +513,7 @@ class AnnotationEditorLayer {
// The editor will be correctly moved into the DOM (see fixAndSetPosition).
editor.fixAndSetPosition();
editor.onceAdded();
editor.onceAdded(/* focus = */ !this.#isEnabling);
this.#uiManager.addToAnnotationStorage(editor);
editor._reportTelemetry(editor.telemetryInitialData);
}

View file

@ -345,7 +345,7 @@ class DrawingEditor extends AnnotationEditor {
}
/** @inheritdoc */
onceAdded() {
onceAdded(focus) {
if (!this.annotationElementId) {
this.parent.addUndoableEditor(this);
}
@ -354,7 +354,7 @@ class DrawingEditor extends AnnotationEditor {
this.#mustBeCommitted = false;
this.commit();
this.parent.setSelected(this);
if (this.isOnScreen) {
if (focus && this.isOnScreen) {
this.div.focus();
}
}

View file

@ -1367,8 +1367,9 @@ class AnnotationEditor {
/**
* Executed once this editor has been rendered.
* @param {boolean} focus - true if the editor should be focused.
*/
onceAdded() {}
onceAdded(focus) {}
/**
* Check if the editor contains something.

View file

@ -363,13 +363,15 @@ class FreeTextEditor extends AnnotationEditor {
}
/** @inheritdoc */
onceAdded() {
onceAdded(focus) {
if (this.width) {
// The editor was created in using ctrl+c.
return;
}
this.enableEditMode();
this.editorDiv.focus();
if (focus) {
this.editorDiv.focus();
}
if (this._initialOptions?.isCentered) {
this.center();
}

View file

@ -439,11 +439,13 @@ class HighlightEditor extends AnnotationEditor {
}
/** @inheritdoc */
onceAdded() {
onceAdded(focus) {
if (!this.annotationElementId) {
this.parent.addUndoableEditor(this);
}
this.div.focus();
if (focus) {
this.div.focus();
}
}
/** @inheritdoc */

View file

@ -338,9 +338,11 @@ class StampEditor extends AnnotationEditor {
}
/** @inheritdoc */
onceAdded() {
onceAdded(focus) {
this._isDraggable = true;
this.div.focus();
if (focus) {
this.div.focus();
}
}
/** @inheritdoc */