1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[Editor] Avoid an extra new line when serializing a FreeText annotation (bug 1897909)

The extra new line is added because of using shift+enter to add a new line
in the text editor.
This commit is contained in:
Calixte Denizet 2024-09-12 15:35:15 +02:00
parent 1ab9ab67ee
commit 85e8bac45d
2 changed files with 51 additions and 0 deletions

View file

@ -403,8 +403,16 @@ class FreeTextEditor extends AnnotationEditor {
// We don't use innerText because there are some bugs with line breaks.
const buffer = [];
this.editorDiv.normalize();
let prevChild = null;
for (const child of this.editorDiv.childNodes) {
if (prevChild?.nodeType === Node.TEXT_NODE && child.nodeName === "BR") {
// It can happen if the user uses shift+enter to add a new line.
// If we don't skip it, we'll end up with an extra line (one for the
// text and one for the br element).
continue;
}
buffer.push(FreeTextEditor.#getNodeContent(child));
prevChild = child;
}
return buffer.join("\n");
}