From b1cc4d5d883cbfad7a4665c1e5614941dd008610 Mon Sep 17 00:00:00 2001 From: "tamas.kiss" Date: Sat, 28 May 2016 19:07:20 +0200 Subject: [PATCH] Allow zooming with ctrl+mousewheel combination related #6978 --- src/vs/base/browser/browser.ts | 27 +++++++++++++++++++ .../browser/ui/scrollbar/scrollableElement.ts | 8 ++++++ src/vs/editor/browser/config/configuration.ts | 1 + .../common/config/commonEditorConfig.ts | 4 +++ 4 files changed, 40 insertions(+) diff --git a/src/vs/base/browser/browser.ts b/src/vs/base/browser/browser.ts index f0b00dd77aeaf..77714ff3003b7 100644 --- a/src/vs/base/browser/browser.ts +++ b/src/vs/base/browser/browser.ts @@ -14,12 +14,16 @@ class ZoomManager { public static INSTANCE = new ZoomManager(); private _zoomLevel: number = 0; + private _editorZoomLevel: number = 0; private _pixelRatioCache: number = 0; private _pixelRatioComputed: boolean = false; private _onDidChangeZoomLevel: Emitter = new Emitter(); public onDidChangeZoomLevel:Event = this._onDidChangeZoomLevel.event; + private _onDidChangeEditorZoomLevel: Emitter = new Emitter(); + public onDidChangeEditorZoomLevel:Event = this._onDidChangeEditorZoomLevel.event; + public getZoomLevel(): number { return this._zoomLevel; } @@ -34,6 +38,19 @@ class ZoomManager { this._onDidChangeZoomLevel.fire(this._zoomLevel); } + public getEditorZoomLevel(): number { + return this._editorZoomLevel; + } + + public setEditorZoomLevel(zoomLevel:number): void { + if (this._editorZoomLevel === zoomLevel) { + return; + } + + this._editorZoomLevel = zoomLevel; + this._onDidChangeZoomLevel.fire(this._editorZoomLevel); + } + public getPixelRatio(): number { if (!this._pixelRatioComputed) { this._pixelRatioCache = this._computePixelRatio(); @@ -66,6 +83,16 @@ export function setZoomLevel(zoomLevel:number): void { export function onDidChangeZoomLevel(callback:(zoomLevel:number)=>void): IDisposable { return ZoomManager.INSTANCE.onDidChangeZoomLevel(callback); } +export function getEditorZoomLevel(): number { + return ZoomManager.INSTANCE.getEditorZoomLevel(); +} +export function setEditorZoomLevel(zoomLevel:number): void { + let zoomLevelNormalized = Math.min(Math.max(-9, zoomLevel), 9); + ZoomManager.INSTANCE.setEditorZoomLevel(zoomLevelNormalized); +} +export function onDidChangeEditorZoomLevel(callback:(zoomLevel:number)=>void): IDisposable { + return ZoomManager.INSTANCE.onDidChangeEditorZoomLevel(callback); +} const userAgent = navigator.userAgent; diff --git a/src/vs/base/browser/ui/scrollbar/scrollableElement.ts b/src/vs/base/browser/ui/scrollbar/scrollableElement.ts index dd15d50c379b4..ba0aa48c942b8 100644 --- a/src/vs/base/browser/ui/scrollbar/scrollableElement.ts +++ b/src/vs/base/browser/ui/scrollbar/scrollableElement.ts @@ -221,6 +221,14 @@ export class ScrollableElement extends Widget { } private _onMouseWheel(e: StandardMouseWheelEvent): void { + let browserEvent = e.browserEvent; + if (browserEvent.ctrlKey){ + let zoomLevel:number = Browser.getEditorZoomLevel(); + let delta = e.deltaY > 0 ? 1 : -1; + zoomLevel += delta; + Browser.setEditorZoomLevel(zoomLevel); + return; + } if (Platform.isMacintosh && e.browserEvent && this._options.saveLastScrollTimeOnClassName) { // Mark dom node with timestamp of wheel event let target = e.browserEvent.target; diff --git a/src/vs/editor/browser/config/configuration.ts b/src/vs/editor/browser/config/configuration.ts index 99f6312815b92..3435b0fe657a0 100644 --- a/src/vs/editor/browser/config/configuration.ts +++ b/src/vs/editor/browser/config/configuration.ts @@ -243,6 +243,7 @@ export class Configuration extends CommonEditorConfiguration { } this._register(browser.onDidChangeZoomLevel(_ => this._recomputeOptions())); + this._register(browser.onDidChangeEditorZoomLevel(_ => this._recomputeOptions())); } private _onReferenceDomElementSizeChanged(): void { diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 28bf7d6f603c7..dd60725e9c1b8 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -15,6 +15,7 @@ import {DefaultConfig, DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE, GOLDEN import * as editorCommon from 'vs/editor/common/editorCommon'; import {EditorLayoutProvider} from 'vs/editor/common/viewLayout/editorLayoutProvider'; import {ScrollbarVisibility} from 'vs/base/browser/ui/scrollbar/scrollableElementOptions'; +import * as browser from 'vs/base/browser/browser'; /** * Experimental screen reader support toggle @@ -388,6 +389,9 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed if (lineHeight === 0) { lineHeight = Math.round(GOLDEN_LINE_HEIGHT_RATIO * fontSize); } + let editorZoomLevelMultiplier = 1 + (browser.getEditorZoomLevel() * 0.1); + fontSize *= editorZoomLevelMultiplier; + lineHeight *= editorZoomLevelMultiplier; return InternalEditorOptionsHelper.createInternalEditorOptions( this.getOuterWidth(),