Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow zooming with ctrl+mousewheel combination #6990

Merged
merged 1 commit into from
Jun 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/vs/base/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> = new Emitter<number>();
public onDidChangeZoomLevel:Event<number> = this._onDidChangeZoomLevel.event;

private _onDidChangeEditorZoomLevel: Emitter<number> = new Emitter<number>();
public onDidChangeEditorZoomLevel:Event<number> = this._onDidChangeEditorZoomLevel.event;

public getZoomLevel(): number {
return this._zoomLevel;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/vs/base/browser/ui/scrollbar/scrollableElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <HTMLElement>e.browserEvent.target;
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/browser/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export class Configuration extends CommonEditorConfiguration {
}

this._register(browser.onDidChangeZoomLevel(_ => this._recomputeOptions()));
this._register(browser.onDidChangeEditorZoomLevel(_ => this._recomputeOptions()));
}

private _onReferenceDomElementSizeChanged(): void {
Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down