Skip to content

Commit 2e8b145

Browse files
author
Benjamin Pasero
committed
perf - do not access zoom level when DOM nodes have been created
Saw this showing up as triggering a layout in the browser before and we know for a fact that the zoom level cannot change during startup.
1 parent a4503c2 commit 2e8b145

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

src/vs/workbench/contrib/issue/electron-browser/issueService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
1111
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
1212
import { IWorkbenchExtensionEnablementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
1313
import { webFrame } from 'vs/base/parts/sandbox/electron-sandbox/globals';
14-
import { assign } from 'vs/base/common/objects';
1514
import { IWorkbenchIssueService } from 'vs/workbench/contrib/issue/electron-browser/issue';
1615
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1716
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService';
@@ -49,7 +48,7 @@ export class WorkbenchIssueService implements IWorkbenchIssueService {
4948
};
5049
});
5150
const theme = this.themeService.getColorTheme();
52-
const issueReporterData: IssueReporterData = assign({
51+
const issueReporterData: IssueReporterData = Object.assign({
5352
styles: getIssueReporterStyles(theme),
5453
zoomLevel: webFrame.getZoomLevel(),
5554
enabledExtensions: extensionData,

src/vs/workbench/electron-browser/window.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ export class NativeWindow extends Disposable {
230230
});
231231

232232
// Zoom level changes
233-
this.updateWindowZoomLevel();
233+
this.updateWindowZoomLevel(false);
234234
this._register(this.configurationService.onDidChangeConfiguration(e => {
235235
if (e.affectsConfiguration('window.zoomLevel')) {
236-
this.updateWindowZoomLevel();
236+
this.updateWindowZoomLevel(true);
237237
} else if (e.affectsConfiguration('keyboard.touchbar.enabled') || e.affectsConfiguration('keyboard.touchbar.ignored')) {
238238
this.updateTouchbarMenu();
239239
}
@@ -326,28 +326,28 @@ export class NativeWindow extends Disposable {
326326
}
327327
}
328328

329-
private updateWindowZoomLevel(): void {
330-
const windowConfig: IWindowsConfiguration = this.configurationService.getValue<IWindowsConfiguration>();
329+
private updateWindowZoomLevel(fromEvent: boolean): void {
330+
const windowConfig = this.configurationService.getValue<IWindowsConfiguration>();
331331

332-
let newZoomLevel = 0;
332+
let configuredZoomLevel = 0;
333333
if (windowConfig.window && typeof windowConfig.window.zoomLevel === 'number') {
334-
newZoomLevel = windowConfig.window.zoomLevel;
334+
configuredZoomLevel = windowConfig.window.zoomLevel;
335335

336336
// Leave early if the configured zoom level did not change (https://github.com/Microsoft/vscode/issues/1536)
337-
if (this.previousConfiguredZoomLevel === newZoomLevel) {
337+
if (this.previousConfiguredZoomLevel === configuredZoomLevel) {
338338
return;
339339
}
340340

341-
this.previousConfiguredZoomLevel = newZoomLevel;
341+
this.previousConfiguredZoomLevel = configuredZoomLevel;
342342
}
343343

344-
if (webFrame.getZoomLevel() !== newZoomLevel) {
345-
webFrame.setZoomLevel(newZoomLevel);
344+
if (fromEvent && webFrame.getZoomLevel() !== configuredZoomLevel) {
345+
webFrame.setZoomLevel(configuredZoomLevel);
346346
browser.setZoomFactor(webFrame.getZoomFactor());
347-
// See https://github.com/Microsoft/vscode/issues/26151
348347
// Cannot be trusted because the webFrame might take some time
349348
// until it really applies the new zoom level
350-
browser.setZoomLevel(webFrame.getZoomLevel(), /*isTrusted*/false);
349+
// See https://github.com/Microsoft/vscode/issues/26151
350+
browser.setZoomLevel(webFrame.getZoomLevel(), false /* isTrusted */);
351351
}
352352
}
353353

src/vs/workbench/electron-sandbox/actions/windowActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ export abstract class BaseZoomAction extends Action {
6565
const applyZoom = () => {
6666
webFrame.setZoomLevel(level);
6767
browser.setZoomFactor(webFrame.getZoomFactor());
68-
// See https://github.com/Microsoft/vscode/issues/26151
6968
// Cannot be trusted because the webFrame might take some time
7069
// until it really applies the new zoom level
71-
browser.setZoomLevel(webFrame.getZoomLevel(), /*isTrusted*/false);
70+
// See https://github.com/Microsoft/vscode/issues/26151
71+
browser.setZoomLevel(webFrame.getZoomLevel(), false /* isTrusted */);
7272
};
7373

7474
await this.configurationService.updateValue(BaseZoomAction.SETTING_KEY, level);

0 commit comments

Comments
 (0)