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:
commit
e98a813e09
2 changed files with 53 additions and 6 deletions
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue