Merge pull request #20458 from calixteman/fix_firstchild

Don't use firstChild/lastChild when getting elements (follow-up of #20447)
This commit is contained in:
Tim van der Meij 2025-11-27 21:34:56 +01:00 committed by GitHub
commit 40b52fa43a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 20 additions and 18 deletions

View File

@ -992,7 +992,7 @@ function renderRichText({ html, dir, className }, container) {
intent: "richText",
});
}
fragment.firstChild.classList.add("richText", className);
fragment.firstElementChild.classList.add("richText", className);
container.append(fragment);
}

View File

@ -208,8 +208,8 @@ class DrawLayer {
}
}
if (path) {
const defs = element.firstChild;
const pathElement = defs.firstChild;
const defs = element.firstElementChild;
const pathElement = defs.firstElementChild;
this.#updateProperties(pathElement, path);
}
}

View File

@ -183,7 +183,7 @@ class ColorPicker {
return;
}
if (event.target === this.#button) {
this.#dropdown.firstChild?.focus();
this.#dropdown.firstElementChild?.focus();
return;
}
event.target.nextSibling?.focus();
@ -191,7 +191,7 @@ class ColorPicker {
_moveToPrevious(event) {
if (
event.target === this.#dropdown?.firstChild ||
event.target === this.#dropdown?.firstElementChild ||
event.target === this.#button
) {
if (this.#isDropdownVisible) {
@ -210,7 +210,7 @@ class ColorPicker {
this.#openDropdown(event);
return;
}
this.#dropdown.firstChild?.focus();
this.#dropdown.firstElementChild?.focus();
}
_moveToEnd(event) {
@ -218,7 +218,7 @@ class ColorPicker {
this.#openDropdown(event);
return;
}
this.#dropdown.lastChild?.focus();
this.#dropdown.lastElementChild?.focus();
}
#keyDown(event) {

View File

@ -2051,11 +2051,13 @@ class AnnotationEditor {
// on the top-left one.
if (nextFirstPosition < firstPosition) {
for (let i = 0; i < firstPosition - nextFirstPosition; i++) {
this.#resizersDiv.append(this.#resizersDiv.firstChild);
this.#resizersDiv.append(this.#resizersDiv.firstElementChild);
}
} else if (nextFirstPosition > firstPosition) {
for (let i = 0; i < nextFirstPosition - firstPosition; i++) {
this.#resizersDiv.firstChild.before(this.#resizersDiv.lastChild);
this.#resizersDiv.firstElementChild.before(
this.#resizersDiv.lastElementChild
);
}
}
@ -2069,7 +2071,7 @@ class AnnotationEditor {
this.#setResizerTabIndex(0);
this.#isResizerEnabledForKeyboard = true;
this.#resizersDiv.firstChild.focus({ focusVisible: true });
this.#resizersDiv.firstElementChild.focus({ focusVisible: true });
event.preventDefault();
event.stopImmediatePropagation();
}
@ -2397,12 +2399,12 @@ class AnnotationEditor {
}
resetAnnotationElement(annotation) {
const { firstChild } = annotation.container;
const { firstElementChild } = annotation.container;
if (
firstChild?.nodeName === "DIV" &&
firstChild.classList.contains("annotationContent")
firstElementChild?.nodeName === "DIV" &&
firstElementChild.classList.contains("annotationContent")
) {
firstChild.remove();
firstElementChild.remove();
}
}
}

View File

@ -392,8 +392,8 @@ class CommentSidebar {
return;
}
this.#setDate(element.firstChild, modificationDate || creationDate);
this.#setText(element.lastChild, richText, contentsObj);
this.#setDate(element.firstElementChild, modificationDate || creationDate);
this.#setText(element.lastElementChild, richText, contentsObj);
this.#annotations.splice(index, 1);
index = binarySearchFirstItem(

View File

@ -444,7 +444,7 @@ class NewAltTextManager {
}
#close() {
const canvas = this.#imagePreview.firstChild;
const canvas = this.#imagePreview.firstElementChild;
canvas.remove();
canvas.width = canvas.height = 0;
this.#imageData = null;
@ -619,7 +619,7 @@ class ImageAltTextSettings {
async #download(isFromUI = false) {
if (isFromUI) {
this.#downloadModelButton.disabled = true;
const span = this.#downloadModelButton.firstChild;
const span = this.#downloadModelButton.firstElementChild;
span.setAttribute(
"data-l10n-id",
"pdfjs-editor-alt-text-settings-downloading-model-button"