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

[Editor] Extract all the lines when adding a FreeText annotation

Fixes #17079.
This commit is contained in:
Calixte Denizet 2024-01-14 19:06:06 +01:00
parent 0d011472a4
commit 9765d57a26
2 changed files with 53 additions and 6 deletions

View file

@ -386,13 +386,14 @@ class FreeTextEditor extends AnnotationEditor {
* @returns {string}
*/
#extractText() {
const divs = this.editorDiv.getElementsByTagName("div");
if (divs.length === 0) {
return this.editorDiv.innerText;
}
// We don't use innerText because there are some bugs with line breaks.
const buffer = [];
for (const div of divs) {
buffer.push(div.innerText.replace(/\r\n?|\n/, ""));
this.editorDiv.normalize();
const EOL_PATTERN = /\r\n?|\n/g;
for (const child of this.editorDiv.childNodes) {
const content =
child.nodeType === Node.TEXT_NODE ? child.nodeValue : child.innerText;
buffer.push(content.replaceAll(EOL_PATTERN, ""));
}
return buffer.join("\n");
}