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

Merge pull request #17511 from calixteman/issue17079

[Editor] Extract all the lines when adding a FreeText annotation
This commit is contained in:
calixteman 2024-01-15 10:40:49 +01:00 committed by GitHub
commit e98a813e09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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");
}