mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[Editor] Allow to undo/redo committed text modifications for FreeText
This commit is contained in:
parent
9cd84aa0b2
commit
2f0bb9dc2f
2 changed files with 111 additions and 9 deletions
|
@ -355,8 +355,26 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
}
|
||||
|
||||
this.disableEditMode();
|
||||
this.#content = this.#extractText().trimEnd();
|
||||
const savedText = this.#content;
|
||||
const newText = (this.#content = this.#extractText().trimEnd());
|
||||
if (savedText === newText) {
|
||||
return;
|
||||
}
|
||||
|
||||
const setText = text => {
|
||||
this.#content = text;
|
||||
this.#setContent();
|
||||
this.#setEditorDimensions();
|
||||
};
|
||||
this.addCommands({
|
||||
cmd: () => {
|
||||
setText(newText);
|
||||
},
|
||||
undo: () => {
|
||||
setText(savedText);
|
||||
},
|
||||
mustExec: false,
|
||||
});
|
||||
this.#setEditorDimensions();
|
||||
}
|
||||
|
||||
|
@ -466,14 +484,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
this.height * parentHeight
|
||||
);
|
||||
|
||||
for (const line of this.#content.split("\n")) {
|
||||
const div = document.createElement("div");
|
||||
div.append(
|
||||
line ? document.createTextNode(line) : document.createElement("br")
|
||||
);
|
||||
this.editorDiv.append(div);
|
||||
}
|
||||
|
||||
this.#setContent();
|
||||
this.div.draggable = true;
|
||||
this.editorDiv.contentEditable = false;
|
||||
} else {
|
||||
|
@ -484,6 +495,20 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
return this.div;
|
||||
}
|
||||
|
||||
#setContent() {
|
||||
this.editorDiv.replaceChildren();
|
||||
if (!this.#content) {
|
||||
return;
|
||||
}
|
||||
for (const line of this.#content.split("\n")) {
|
||||
const div = document.createElement("div");
|
||||
div.append(
|
||||
line ? document.createTextNode(line) : document.createElement("br")
|
||||
);
|
||||
this.editorDiv.append(div);
|
||||
}
|
||||
}
|
||||
|
||||
get contentDiv() {
|
||||
return this.editorDiv;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue