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

[Editor] Fix test failures in m-c because of the new FreeText undo/redo stuff

This commit is contained in:
Calixte Denizet 2023-06-08 12:50:30 +02:00
parent 22d350cae6
commit baebf7b26d
4 changed files with 51 additions and 39 deletions

View file

@ -330,36 +330,6 @@ class AnnotationEditorLayer {
}
}
/**
* Add a new editor and make this addition undoable.
* @param {AnnotationEditor} editor
*/
addANewEditor(editor) {
const cmd = () => {
this.addOrRebuild(editor);
};
const undo = () => {
editor.remove();
};
this.addCommands({ cmd, undo, mustExec: true });
}
/**
* Add a new editor and make this addition undoable.
* @param {AnnotationEditor} editor
*/
addUndoableEditor(editor) {
const cmd = () => {
this.addOrRebuild(editor);
};
const undo = () => {
editor.remove();
};
this.addCommands({ cmd, undo, mustExec: false });
}
/**
* Get an id for an editor.
* @returns {string}

View file

@ -472,6 +472,7 @@ class AnnotationEditor {
*/
rebuild() {
this.div?.addEventListener("focusin", this.#boundFocusin);
this.div?.addEventListener("focusout", this.#boundFocusout);
}
/**

View file

@ -46,8 +46,6 @@ class FreeTextEditor extends AnnotationEditor {
#editorDivId = `${this.id}-editor`;
#hasAlreadyBeenCommitted = false;
#fontSize;
static _freeTextDefaultContent = "";
@ -355,13 +353,6 @@ class FreeTextEditor extends AnnotationEditor {
}
super.commit();
if (!this.#hasAlreadyBeenCommitted) {
// This editor has something and it's the first time
// it's commited so we can add it in the undo/redo stack.
this.#hasAlreadyBeenCommitted = true;
this.parent.addUndoableEditor(this);
}
this.disableEditMode();
const savedText = this.#content;
const newText = (this.#content = this.#extractText().trimEnd());
@ -371,7 +362,12 @@ class FreeTextEditor extends AnnotationEditor {
const setText = text => {
this.#content = text;
if (!text) {
this.remove();
return;
}
this.#setContent();
this.rebuild();
this.#setEditorDimensions();
};
this.addCommands({