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", intent: "richText",
}); });
} }
fragment.firstChild.classList.add("richText", className); fragment.firstElementChild.classList.add("richText", className);
container.append(fragment); container.append(fragment);
} }

View File

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

View File

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

View File

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

View File

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

View File

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