diff --git a/src/vs/platform/window/electron-sandbox/window.ts b/src/vs/platform/window/electron-sandbox/window.ts index d8a3301ff3c..ab0e479d1a3 100644 --- a/src/vs/platform/window/electron-sandbox/window.ts +++ b/src/vs/platform/window/electron-sandbox/window.ts @@ -14,11 +14,16 @@ export enum ApplyZoomTarget { ALL_WINDOWS } +export const MAX_ZOOM_LEVEL = 8; +export const MIN_ZOOM_LEVEL = -8; + /** * Apply a zoom level to the window. Also sets it in our in-memory * browser helper so that it can be accessed in non-electron layers. */ export function applyZoom(zoomLevel: number, target: ApplyZoomTarget | Window): void { + zoomLevel = Math.min(Math.max(zoomLevel, MIN_ZOOM_LEVEL), MAX_ZOOM_LEVEL); // cap zoom levels between -8 and 8 + const targetWindows: Window[] = []; if (target === ApplyZoomTarget.ACTIVE_WINDOW) { targetWindows.push(getActiveWindow()); diff --git a/src/vs/workbench/electron-sandbox/actions/windowActions.ts b/src/vs/workbench/electron-sandbox/actions/windowActions.ts index 8f5a4a5f0f0..2d49534034c 100644 --- a/src/vs/workbench/electron-sandbox/actions/windowActions.ts +++ b/src/vs/workbench/electron-sandbox/actions/windowActions.ts @@ -6,7 +6,7 @@ import 'vs/css!./media/actions'; import { URI } from 'vs/base/common/uri'; import { localize, localize2 } from 'vs/nls'; -import { ApplyZoomTarget, applyZoom } from 'vs/platform/window/electron-sandbox/window'; +import { ApplyZoomTarget, MAX_ZOOM_LEVEL, MIN_ZOOM_LEVEL, applyZoom } from 'vs/platform/window/electron-sandbox/window'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { getZoomLevel } from 'vs/base/browser/browser'; import { FileKind } from 'vs/platform/files/common/files'; @@ -68,9 +68,6 @@ abstract class BaseZoomAction extends Action2 { private static readonly ZOOM_LEVEL_SETTING_KEY = 'window.zoomLevel'; private static readonly ZOOM_PER_WINDOW_SETTING_KEY = 'window.zoomPerWindow'; - private static readonly MAX_ZOOM_LEVEL = 8; - private static readonly MIN_ZOOM_LEVEL = -8; - constructor(desc: Readonly) { super(desc); } @@ -108,7 +105,7 @@ abstract class BaseZoomAction extends Action2 { level = Math.round(level); // when reaching smallest zoom, prevent fractional zoom levels - if (level > BaseZoomAction.MAX_ZOOM_LEVEL || level < BaseZoomAction.MIN_ZOOM_LEVEL) { + if (level > MAX_ZOOM_LEVEL || level < MIN_ZOOM_LEVEL) { return; // https://github.com/microsoft/vscode/issues/48357 } diff --git a/src/vs/workbench/electron-sandbox/desktop.contribution.ts b/src/vs/workbench/electron-sandbox/desktop.contribution.ts index f5f5772fccd..3887dd8856a 100644 --- a/src/vs/workbench/electron-sandbox/desktop.contribution.ts +++ b/src/vs/workbench/electron-sandbox/desktop.contribution.ts @@ -27,6 +27,7 @@ import { ShutdownReason } from 'vs/workbench/services/lifecycle/common/lifecycle import { NativeWindow } from 'vs/workbench/electron-sandbox/window'; import { ModifierKeyEmitter } from 'vs/base/browser/dom'; import { applicationConfigurationNodeBase, securityConfigurationNodeBase } from 'vs/workbench/common/configuration'; +import { MAX_ZOOM_LEVEL, MIN_ZOOM_LEVEL } from 'vs/platform/window/electron-sandbox/window'; // Actions (function registerActions(): void { @@ -190,8 +191,8 @@ import { applicationConfigurationNodeBase, securityConfigurationNodeBase } from 'window.zoomLevel': { 'type': 'number', 'default': 0, - 'minimum': -8, - 'maximum': 8, + 'minimum': MIN_ZOOM_LEVEL, + 'maximum': MAX_ZOOM_LEVEL, '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#`'), ignoreSync: true, tags: ['accessibility']