Skip to content

Commit 40b52fa

Browse files
Merge pull request #20458 from calixteman/fix_firstchild
Don't use firstChild/lastChild when getting elements (follow-up of #20447)
2 parents 08074cf + 029cae2 commit 40b52fa

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

src/display/display_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ function renderRichText({ html, dir, className }, container) {
992992
intent: "richText",
993993
});
994994
}
995-
fragment.firstChild.classList.add("richText", className);
995+
fragment.firstElementChild.classList.add("richText", className);
996996
container.append(fragment);
997997
}
998998

src/display/draw_layer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ class DrawLayer {
208208
}
209209
}
210210
if (path) {
211-
const defs = element.firstChild;
212-
const pathElement = defs.firstChild;
211+
const defs = element.firstElementChild;
212+
const pathElement = defs.firstElementChild;
213213
this.#updateProperties(pathElement, path);
214214
}
215215
}

src/display/editor/color_picker.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ class ColorPicker {
183183
return;
184184
}
185185
if (event.target === this.#button) {
186-
this.#dropdown.firstChild?.focus();
186+
this.#dropdown.firstElementChild?.focus();
187187
return;
188188
}
189189
event.target.nextSibling?.focus();
190190
}
191191

192192
_moveToPrevious(event) {
193193
if (
194-
event.target === this.#dropdown?.firstChild ||
194+
event.target === this.#dropdown?.firstElementChild ||
195195
event.target === this.#button
196196
) {
197197
if (this.#isDropdownVisible) {
@@ -210,15 +210,15 @@ class ColorPicker {
210210
this.#openDropdown(event);
211211
return;
212212
}
213-
this.#dropdown.firstChild?.focus();
213+
this.#dropdown.firstElementChild?.focus();
214214
}
215215

216216
_moveToEnd(event) {
217217
if (!this.#isDropdownVisible) {
218218
this.#openDropdown(event);
219219
return;
220220
}
221-
this.#dropdown.lastChild?.focus();
221+
this.#dropdown.lastElementChild?.focus();
222222
}
223223

224224
#keyDown(event) {

src/display/editor/editor.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,11 +2051,13 @@ class AnnotationEditor {
20512051
// on the top-left one.
20522052
if (nextFirstPosition < firstPosition) {
20532053
for (let i = 0; i < firstPosition - nextFirstPosition; i++) {
2054-
this.#resizersDiv.append(this.#resizersDiv.firstChild);
2054+
this.#resizersDiv.append(this.#resizersDiv.firstElementChild);
20552055
}
20562056
} else if (nextFirstPosition > firstPosition) {
20572057
for (let i = 0; i < nextFirstPosition - firstPosition; i++) {
2058-
this.#resizersDiv.firstChild.before(this.#resizersDiv.lastChild);
2058+
this.#resizersDiv.firstElementChild.before(
2059+
this.#resizersDiv.lastElementChild
2060+
);
20592061
}
20602062
}
20612063

@@ -2069,7 +2071,7 @@ class AnnotationEditor {
20692071

20702072
this.#setResizerTabIndex(0);
20712073
this.#isResizerEnabledForKeyboard = true;
2072-
this.#resizersDiv.firstChild.focus({ focusVisible: true });
2074+
this.#resizersDiv.firstElementChild.focus({ focusVisible: true });
20732075
event.preventDefault();
20742076
event.stopImmediatePropagation();
20752077
}
@@ -2397,12 +2399,12 @@ class AnnotationEditor {
23972399
}
23982400

23992401
resetAnnotationElement(annotation) {
2400-
const { firstChild } = annotation.container;
2402+
const { firstElementChild } = annotation.container;
24012403
if (
2402-
firstChild?.nodeName === "DIV" &&
2403-
firstChild.classList.contains("annotationContent")
2404+
firstElementChild?.nodeName === "DIV" &&
2405+
firstElementChild.classList.contains("annotationContent")
24042406
) {
2405-
firstChild.remove();
2407+
firstElementChild.remove();
24062408
}
24072409
}
24082410
}

web/comment_manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ class CommentSidebar {
392392
return;
393393
}
394394

395-
this.#setDate(element.firstChild, modificationDate || creationDate);
396-
this.#setText(element.lastChild, richText, contentsObj);
395+
this.#setDate(element.firstElementChild, modificationDate || creationDate);
396+
this.#setText(element.lastElementChild, richText, contentsObj);
397397

398398
this.#annotations.splice(index, 1);
399399
index = binarySearchFirstItem(

web/new_alt_text_manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class NewAltTextManager {
444444
}
445445

446446
#close() {
447-
const canvas = this.#imagePreview.firstChild;
447+
const canvas = this.#imagePreview.firstElementChild;
448448
canvas.remove();
449449
canvas.width = canvas.height = 0;
450450
this.#imageData = null;
@@ -619,7 +619,7 @@ class ImageAltTextSettings {
619619
async #download(isFromUI = false) {
620620
if (isFromUI) {
621621
this.#downloadModelButton.disabled = true;
622-
const span = this.#downloadModelButton.firstChild;
622+
const span = this.#downloadModelButton.firstElementChild;
623623
span.setAttribute(
624624
"data-l10n-id",
625625
"pdfjs-editor-alt-text-settings-downloading-model-button"

0 commit comments

Comments
 (0)