mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[Editor] Add the parent tag id (if any) to the serialized editors (bug 1845087)
The tag id will be useful in order to update the StructTree when saving the pdf.
This commit is contained in:
parent
3e32d87be7
commit
c6f7e722c9
7 changed files with 69 additions and 8 deletions
|
@ -179,17 +179,18 @@ class TextAccessibilityManager {
|
|||
* in order to correctly position this editor in the text flow.
|
||||
* @param {HTMLElement} element
|
||||
* @param {boolean} isRemovable
|
||||
* @returns {string|null} The id in the struct tree if any.
|
||||
*/
|
||||
addPointerInTextLayer(element, isRemovable) {
|
||||
const { id } = element;
|
||||
if (!id) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.#enabled) {
|
||||
// The text layer needs to be there, so we postpone the association.
|
||||
this.#waitingElements.set(element, isRemovable);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isRemovable) {
|
||||
|
@ -198,7 +199,7 @@ class TextAccessibilityManager {
|
|||
|
||||
const children = this.#textChildren;
|
||||
if (!children || children.length === 0) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
const index = binarySearchFirstItem(
|
||||
|
@ -208,20 +209,25 @@ class TextAccessibilityManager {
|
|||
);
|
||||
|
||||
const nodeIndex = Math.max(0, index - 1);
|
||||
this.#addIdToAriaOwns(id, children[nodeIndex]);
|
||||
const child = children[nodeIndex];
|
||||
this.#addIdToAriaOwns(id, child);
|
||||
this.#textNodes.set(id, nodeIndex);
|
||||
|
||||
const parent = child.parentNode;
|
||||
return parent?.classList.contains("markedContent") ? parent.id : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a div in the DOM in order to respect the visual order.
|
||||
* @param {HTMLDivElement} element
|
||||
* @returns {string|null} The id in the struct tree if any.
|
||||
*/
|
||||
moveElementInDOM(container, element, contentElement, isRemovable) {
|
||||
this.addPointerInTextLayer(contentElement, isRemovable);
|
||||
const id = this.addPointerInTextLayer(contentElement, isRemovable);
|
||||
|
||||
if (!container.hasChildNodes()) {
|
||||
container.append(element);
|
||||
return;
|
||||
return id;
|
||||
}
|
||||
|
||||
const children = Array.from(container.childNodes).filter(
|
||||
|
@ -229,7 +235,7 @@ class TextAccessibilityManager {
|
|||
);
|
||||
|
||||
if (children.length === 0) {
|
||||
return;
|
||||
return id;
|
||||
}
|
||||
|
||||
const elementToCompare = contentElement || element;
|
||||
|
@ -247,6 +253,8 @@ class TextAccessibilityManager {
|
|||
} else {
|
||||
children[index - 1].after(element);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue