mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[Editor] When in non-editing mode, add a new editor only once the editing mode has switched
Switching to an editing mode can be asynchronous (e.g. if an editable annotation exists on a visible page), so we must add a new editor only when the page rendering is done.
This commit is contained in:
parent
f9e3b6bcc4
commit
6dd75c0e62
5 changed files with 68 additions and 10 deletions
|
@ -916,6 +916,18 @@ class AnnotationEditorUIManager {
|
|||
this.#altTextManager?.editAltText(this, editor);
|
||||
}
|
||||
|
||||
switchToMode(mode, callback) {
|
||||
// Switching to a mode can be asynchronous.
|
||||
this._eventBus.on("annotationeditormodechanged", callback, {
|
||||
once: true,
|
||||
signal: this._signal,
|
||||
});
|
||||
this._eventBus.dispatch("showannotationeditorui", {
|
||||
source: this,
|
||||
mode,
|
||||
});
|
||||
}
|
||||
|
||||
onPageChanging({ pageNumber }) {
|
||||
this.#currentPageIndex = pageNumber - 1;
|
||||
}
|
||||
|
@ -1002,16 +1014,11 @@ class AnnotationEditorUIManager {
|
|||
return;
|
||||
}
|
||||
selection.empty();
|
||||
if (this.#mode === AnnotationEditorType.NONE) {
|
||||
this._eventBus.dispatch("showannotationeditorui", {
|
||||
source: this,
|
||||
mode: AnnotationEditorType.HIGHLIGHT,
|
||||
});
|
||||
this.showAllEditors("highlight", true, /* updateButton = */ true);
|
||||
}
|
||||
|
||||
const layer = this.#getLayerForTextLayer(textLayer);
|
||||
if (layer) {
|
||||
layer.createAndAddNewEditor({ x: 0, y: 0 }, false, {
|
||||
const isNoneMode = this.#mode === AnnotationEditorType.NONE;
|
||||
const callback = () => {
|
||||
layer?.createAndAddNewEditor({ x: 0, y: 0 }, false, {
|
||||
methodOfCreation,
|
||||
boxes,
|
||||
anchorNode,
|
||||
|
@ -1020,7 +1027,15 @@ class AnnotationEditorUIManager {
|
|||
focusOffset,
|
||||
text,
|
||||
});
|
||||
if (isNoneMode) {
|
||||
this.showAllEditors("highlight", true, /* updateButton = */ true);
|
||||
}
|
||||
};
|
||||
if (isNoneMode) {
|
||||
this.switchToMode(AnnotationEditorType.HIGHLIGHT, callback);
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
#displayHighlightToolbar() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue