Skip to content

Commit b5f2bd8

Browse files
Merge pull request #14910 from Snuffleupagus/adjustScaleWidth-animationStarted
Ensure that setting the width of the zoom dropdown works correctly (PR 14028 follow-up)
2 parents 96b125f + efe3cb2 commit b5f2bd8

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

web/toolbar.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class Toolbar {
170170

171171
this.eventBus._on("localized", () => {
172172
this._wasLocalized = true;
173-
this._adjustScaleWidth();
173+
this.#adjustScaleWidth();
174174
this._updateUIState(true);
175175
});
176176
}
@@ -237,9 +237,8 @@ class Toolbar {
237237
/**
238238
* Increase the width of the zoom dropdown DOM element if, and only if, it's
239239
* too narrow to fit the *longest* of the localized strings.
240-
* @private
241240
*/
242-
async _adjustScaleWidth() {
241+
async #adjustScaleWidth() {
243242
const { items, l10n } = this;
244243

245244
const predefinedValuesPromise = Promise.all([
@@ -248,6 +247,7 @@ class Toolbar {
248247
l10n.get("page_scale_fit"),
249248
l10n.get("page_scale_width"),
250249
]);
250+
await animationStarted;
251251

252252
const style = getComputedStyle(items.scaleSelect),
253253
scaleSelectContainerWidth = parseInt(
@@ -260,10 +260,8 @@ class Toolbar {
260260
);
261261

262262
// The temporary canvas is used to measure text length in the DOM.
263-
let canvas = document.createElement("canvas");
264-
let ctx = canvas.getContext("2d", { alpha: false });
265-
266-
await animationStarted;
263+
const canvas = document.createElement("canvas");
264+
const ctx = canvas.getContext("2d", { alpha: false });
267265
ctx.font = `${style.fontSize} ${style.fontFamily}`;
268266

269267
let maxWidth = 0;
@@ -283,7 +281,6 @@ class Toolbar {
283281
// immediately, which can greatly reduce memory consumption.
284282
canvas.width = 0;
285283
canvas.height = 0;
286-
canvas = ctx = null;
287284
}
288285
}
289286

0 commit comments

Comments
 (0)