1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[Editor] Edit an existing FreeText annotation in double-clicking on it (bug 1787298)

This commit is contained in:
Calixte Denizet 2023-07-07 15:51:48 +02:00
parent c33e6ceb03
commit 5c5f9af803
8 changed files with 86 additions and 14 deletions

View file

@ -601,6 +601,20 @@ class AnnotationElement {
triggers.classList.add("highlightArea");
}
}
_editOnDoubleClick() {
const {
annotationEditorType: mode,
data: { id: editId },
} = this;
this.container.addEventListener("dblclick", () => {
this.linkService.eventBus?.dispatch("switchannotationeditormode", {
source: this,
mode,
editId,
});
});
}
}
class LinkAnnotationElement extends AnnotationElement {
@ -2217,6 +2231,9 @@ class FreeTextAnnotationElement extends AnnotationElement {
if (!this.data.popupRef) {
this._createPopup();
}
this._editOnDoubleClick();
return this.container;
}
}

View file

@ -621,6 +621,11 @@ class AnnotationEditor {
*/
enableEditing() {}
/**
* The editor is about to be edited.
*/
enterInEditMode() {}
/**
* Get the div which really contains the displayed content.
*/

View file

@ -403,13 +403,18 @@ class FreeTextEditor extends AnnotationEditor {
return this.isInEditMode();
}
/** @inheritdoc */
enterInEditMode() {
this.enableEditMode();
this.editorDiv.focus();
}
/**
* ondblclick callback.
* @param {MouseEvent} event
*/
dblclick(event) {
this.enableEditMode();
this.editorDiv.focus();
this.enterInEditMode();
}
/**
@ -418,8 +423,7 @@ class FreeTextEditor extends AnnotationEditor {
*/
keydown(event) {
if (event.target === this.div && event.key === "Enter") {
this.enableEditMode();
this.editorDiv.focus();
this.enterInEditMode();
}
}

View file

@ -912,17 +912,28 @@ class AnnotationEditorUIManager {
/**
* Change the editor mode (None, FreeText, Ink, ...)
* @param {number} mode
* @param {string|null} editId
*/
updateMode(mode) {
updateMode(mode, editId = null) {
this.#mode = mode;
if (mode === AnnotationEditorType.NONE) {
this.setEditingState(false);
this.#disableAll();
} else {
this.setEditingState(true);
this.#enableAll();
for (const layer of this.#allLayers.values()) {
layer.updateMode(mode);
return;
}
this.setEditingState(true);
this.#enableAll();
for (const layer of this.#allLayers.values()) {
layer.updateMode(mode);
}
if (!editId) {
return;
}
for (const editor of this.#allEditors.values()) {
if (editor.annotationElementId === editId) {
this.setSelected(editor);
editor.enterInEditMode();
break;
}
}
}