[Editor] Edit an existing FreeText annotation in double-clicking on it (bug 1787298)
This commit is contained in:
		
							parent
							
								
									c33e6ceb03
								
							
						
					
					
						commit
						5c5f9af803
					
				@ -601,6 +601,20 @@ class AnnotationElement {
 | 
				
			|||||||
      triggers.classList.add("highlightArea");
 | 
					      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 {
 | 
					class LinkAnnotationElement extends AnnotationElement {
 | 
				
			||||||
@ -2217,6 +2231,9 @@ class FreeTextAnnotationElement extends AnnotationElement {
 | 
				
			|||||||
    if (!this.data.popupRef) {
 | 
					    if (!this.data.popupRef) {
 | 
				
			||||||
      this._createPopup();
 | 
					      this._createPopup();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this._editOnDoubleClick();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return this.container;
 | 
					    return this.container;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -621,6 +621,11 @@ class AnnotationEditor {
 | 
				
			|||||||
   */
 | 
					   */
 | 
				
			||||||
  enableEditing() {}
 | 
					  enableEditing() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The editor is about to be edited.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  enterInEditMode() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Get the div which really contains the displayed content.
 | 
					   * Get the div which really contains the displayed content.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
 | 
				
			|||||||
@ -403,13 +403,18 @@ class FreeTextEditor extends AnnotationEditor {
 | 
				
			|||||||
    return this.isInEditMode();
 | 
					    return this.isInEditMode();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /** @inheritdoc */
 | 
				
			||||||
 | 
					  enterInEditMode() {
 | 
				
			||||||
 | 
					    this.enableEditMode();
 | 
				
			||||||
 | 
					    this.editorDiv.focus();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * ondblclick callback.
 | 
					   * ondblclick callback.
 | 
				
			||||||
   * @param {MouseEvent} event
 | 
					   * @param {MouseEvent} event
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  dblclick(event) {
 | 
					  dblclick(event) {
 | 
				
			||||||
    this.enableEditMode();
 | 
					    this.enterInEditMode();
 | 
				
			||||||
    this.editorDiv.focus();
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
@ -418,8 +423,7 @@ class FreeTextEditor extends AnnotationEditor {
 | 
				
			|||||||
   */
 | 
					   */
 | 
				
			||||||
  keydown(event) {
 | 
					  keydown(event) {
 | 
				
			||||||
    if (event.target === this.div && event.key === "Enter") {
 | 
					    if (event.target === this.div && event.key === "Enter") {
 | 
				
			||||||
      this.enableEditMode();
 | 
					      this.enterInEditMode();
 | 
				
			||||||
      this.editorDiv.focus();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -912,17 +912,28 @@ class AnnotationEditorUIManager {
 | 
				
			|||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Change the editor mode (None, FreeText, Ink, ...)
 | 
					   * Change the editor mode (None, FreeText, Ink, ...)
 | 
				
			||||||
   * @param {number} mode
 | 
					   * @param {number} mode
 | 
				
			||||||
 | 
					   * @param {string|null} editId
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  updateMode(mode) {
 | 
					  updateMode(mode, editId = null) {
 | 
				
			||||||
    this.#mode = mode;
 | 
					    this.#mode = mode;
 | 
				
			||||||
    if (mode === AnnotationEditorType.NONE) {
 | 
					    if (mode === AnnotationEditorType.NONE) {
 | 
				
			||||||
      this.setEditingState(false);
 | 
					      this.setEditingState(false);
 | 
				
			||||||
      this.#disableAll();
 | 
					      this.#disableAll();
 | 
				
			||||||
    } else {
 | 
					      return;
 | 
				
			||||||
      this.setEditingState(true);
 | 
					    }
 | 
				
			||||||
      this.#enableAll();
 | 
					    this.setEditingState(true);
 | 
				
			||||||
      for (const layer of this.#allLayers.values()) {
 | 
					    this.#enableAll();
 | 
				
			||||||
        layer.updateMode(mode);
 | 
					    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;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -1115,6 +1115,39 @@ describe("FreeText Editor", () => {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe("FreeText (edit existing in double clicking on it)", () => {
 | 
				
			||||||
 | 
					    let pages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    beforeAll(async () => {
 | 
				
			||||||
 | 
					      pages = await loadAndWait("freetexts.pdf", ".annotationEditorLayer");
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    afterAll(async () => {
 | 
				
			||||||
 | 
					      await closePages(pages);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it("must move an annotation", async () => {
 | 
				
			||||||
 | 
					      await Promise.all(
 | 
				
			||||||
 | 
					        pages.map(async ([browserName, page]) => {
 | 
				
			||||||
 | 
					          await page.click("[data-annotation-id='26R']", { clickCount: 2 });
 | 
				
			||||||
 | 
					          await page.waitForTimeout(10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const [focusedId, editable] = await page.evaluate(() => {
 | 
				
			||||||
 | 
					            const el = document.activeElement;
 | 
				
			||||||
 | 
					            return [el.id, el.contentEditable];
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					          expect(focusedId)
 | 
				
			||||||
 | 
					            .withContext(`In ${browserName}`)
 | 
				
			||||||
 | 
					            .toEqual("pdfjs_internal_editor_0-editor");
 | 
				
			||||||
 | 
					          expect(editable).withContext(`In ${browserName}`).toEqual("true");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const editorIds = await getEditors(page, "freeText");
 | 
				
			||||||
 | 
					          expect(editorIds.length).withContext(`In ${browserName}`).toEqual(6);
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe("FreeText with popup", () => {
 | 
					  describe("FreeText with popup", () => {
 | 
				
			||||||
    let pages;
 | 
					    let pages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -2518,7 +2518,7 @@ function webViewerPresentationMode() {
 | 
				
			|||||||
  PDFViewerApplication.requestPresentationMode();
 | 
					  PDFViewerApplication.requestPresentationMode();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
function webViewerSwitchAnnotationEditorMode(evt) {
 | 
					function webViewerSwitchAnnotationEditorMode(evt) {
 | 
				
			||||||
  PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
 | 
					  PDFViewerApplication.pdfViewer.annotationEditorMode = evt;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
function webViewerSwitchAnnotationEditorParams(evt) {
 | 
					function webViewerSwitchAnnotationEditorParams(evt) {
 | 
				
			||||||
  PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
 | 
					  PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
 | 
				
			||||||
 | 
				
			|||||||
@ -175,7 +175,9 @@ class PDFPresentationMode {
 | 
				
			|||||||
      this.pdfViewer.currentScaleValue = "page-fit";
 | 
					      this.pdfViewer.currentScaleValue = "page-fit";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (this.#args.annotationEditorMode !== null) {
 | 
					      if (this.#args.annotationEditorMode !== null) {
 | 
				
			||||||
        this.pdfViewer.annotationEditorMode = AnnotationEditorType.NONE;
 | 
					        this.pdfViewer.annotationEditorMode = {
 | 
				
			||||||
 | 
					          mode: AnnotationEditorType.NONE,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }, 0);
 | 
					    }, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -2203,7 +2203,7 @@ class PDFViewer {
 | 
				
			|||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * @param {number} mode - AnnotationEditor mode (None, FreeText, Ink, ...)
 | 
					   * @param {number} mode - AnnotationEditor mode (None, FreeText, Ink, ...)
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  set annotationEditorMode(mode) {
 | 
					  set annotationEditorMode({ mode, editId = null }) {
 | 
				
			||||||
    if (!this.#annotationEditorUIManager) {
 | 
					    if (!this.#annotationEditorUIManager) {
 | 
				
			||||||
      throw new Error(`The AnnotationEditor is not enabled.`);
 | 
					      throw new Error(`The AnnotationEditor is not enabled.`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -2222,7 +2222,7 @@ class PDFViewer {
 | 
				
			|||||||
      mode,
 | 
					      mode,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.#annotationEditorUIManager.updateMode(mode);
 | 
					    this.#annotationEditorUIManager.updateMode(mode, editId);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // eslint-disable-next-line accessor-pairs
 | 
					  // eslint-disable-next-line accessor-pairs
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user