Sanity Bounds for "window.zoomLevel" (fix #152028) (#202682)

This commit is contained in:
Benjamin Pasero
2024-01-17 20:58:54 +01:00
committed by GitHub
parent fe7233fdfb
commit 48905201c0
3 changed files with 10 additions and 7 deletions
@@ -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());
@@ -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<IAction2Options>) {
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
}
@@ -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']