Skip to content

Commit 4890520

Browse files
authored
Sanity Bounds for "window.zoomLevel" (fix microsoft#152028) (microsoft#202682)
1 parent fe7233f commit 4890520

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/vs/platform/window/electron-sandbox/window.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ export enum ApplyZoomTarget {
1414
ALL_WINDOWS
1515
}
1616

17+
export const MAX_ZOOM_LEVEL = 8;
18+
export const MIN_ZOOM_LEVEL = -8;
19+
1720
/**
1821
* Apply a zoom level to the window. Also sets it in our in-memory
1922
* browser helper so that it can be accessed in non-electron layers.
2023
*/
2124
export function applyZoom(zoomLevel: number, target: ApplyZoomTarget | Window): void {
25+
zoomLevel = Math.min(Math.max(zoomLevel, MIN_ZOOM_LEVEL), MAX_ZOOM_LEVEL); // cap zoom levels between -8 and 8
26+
2227
const targetWindows: Window[] = [];
2328
if (target === ApplyZoomTarget.ACTIVE_WINDOW) {
2429
targetWindows.push(getActiveWindow());

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import 'vs/css!./media/actions';
77
import { URI } from 'vs/base/common/uri';
88
import { localize, localize2 } from 'vs/nls';
9-
import { ApplyZoomTarget, applyZoom } from 'vs/platform/window/electron-sandbox/window';
9+
import { ApplyZoomTarget, MAX_ZOOM_LEVEL, MIN_ZOOM_LEVEL, applyZoom } from 'vs/platform/window/electron-sandbox/window';
1010
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1111
import { getZoomLevel } from 'vs/base/browser/browser';
1212
import { FileKind } from 'vs/platform/files/common/files';
@@ -68,9 +68,6 @@ abstract class BaseZoomAction extends Action2 {
6868
private static readonly ZOOM_LEVEL_SETTING_KEY = 'window.zoomLevel';
6969
private static readonly ZOOM_PER_WINDOW_SETTING_KEY = 'window.zoomPerWindow';
7070

71-
private static readonly MAX_ZOOM_LEVEL = 8;
72-
private static readonly MIN_ZOOM_LEVEL = -8;
73-
7471
constructor(desc: Readonly<IAction2Options>) {
7572
super(desc);
7673
}
@@ -108,7 +105,7 @@ abstract class BaseZoomAction extends Action2 {
108105

109106
level = Math.round(level); // when reaching smallest zoom, prevent fractional zoom levels
110107

111-
if (level > BaseZoomAction.MAX_ZOOM_LEVEL || level < BaseZoomAction.MIN_ZOOM_LEVEL) {
108+
if (level > MAX_ZOOM_LEVEL || level < MIN_ZOOM_LEVEL) {
112109
return; // https://github.com/microsoft/vscode/issues/48357
113110
}
114111

src/vs/workbench/electron-sandbox/desktop.contribution.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { ShutdownReason } from 'vs/workbench/services/lifecycle/common/lifecycle
2727
import { NativeWindow } from 'vs/workbench/electron-sandbox/window';
2828
import { ModifierKeyEmitter } from 'vs/base/browser/dom';
2929
import { applicationConfigurationNodeBase, securityConfigurationNodeBase } from 'vs/workbench/common/configuration';
30+
import { MAX_ZOOM_LEVEL, MIN_ZOOM_LEVEL } from 'vs/platform/window/electron-sandbox/window';
3031

3132
// Actions
3233
(function registerActions(): void {
@@ -190,8 +191,8 @@ import { applicationConfigurationNodeBase, securityConfigurationNodeBase } from
190191
'window.zoomLevel': {
191192
'type': 'number',
192193
'default': 0,
193-
'minimum': -8,
194-
'maximum': 8,
194+
'minimum': MIN_ZOOM_LEVEL,
195+
'maximum': MAX_ZOOM_LEVEL,
195196
'markdownDescription': localize({ comment: ['{0} will be a setting name rendered as a link'], key: 'zoomLevel' }, "Adjust the default zoom level for all windows. Each increment above `0` (e.g. `1`) or below (e.g. `-1`) represents zooming `20%` larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity. See {0} for configuring if the 'Zoom In' and 'Zoom Out' commands apply the zoom level to all windows or only the active window.", '`#window.zoomPerWindow#`'),
196197
ignoreSync: true,
197198
tags: ['accessibility']

0 commit comments

Comments
 (0)