mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #16659 from calixteman/edit_freetexts
[Editor] Edit an existing FreeText annotation in double-clicking on it (bug 1787298)
This commit is contained in:
commit
52c98eb751
8 changed files with 86 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -621,6 +621,11 @@ class AnnotationEditor {
|
|||
*/
|
||||
enableEditing() {}
|
||||
|
||||
/**
|
||||
* The editor is about to be edited.
|
||||
*/
|
||||
enterInEditMode() {}
|
||||
|
||||
/**
|
||||
* Get the div which really contains the displayed content.
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue