Skip to content

Commit 453f8fb

Browse files
committed
Add commands to zoom in/out/reset for terminal
Fixes microsoft#204156
1 parent 17e46e2 commit 453f8fb

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed

src/vs/workbench/contrib/terminal/common/terminal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ export const enum TerminalCommandId {
497497
ToggleStickyScroll = 'workbench.action.terminal.toggleStickyScroll',
498498
StartVoice = 'workbench.action.startTerminalVoice',
499499
StopVoice = 'workbench.action.stopTerminalVoice',
500+
FontZoomIn = 'workbench.action.terminal.fontZoomIn',
501+
FontZoomOut = 'workbench.action.terminal.fontZoomOut',
502+
FontZoomReset = 'workbench.action.terminal.fontZoomReset',
500503

501504
// Developer commands
502505

src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ terminalTitle += terminalDescriptors;
3030
let terminalDescription = localize('terminalDescription', "Controls the terminal description, which appears to the right of the title. Variables are substituted based on the context:");
3131
terminalDescription += terminalDescriptors;
3232

33+
export const defaultTerminalFontSize = isMacintosh ? 12 : 14;
34+
3335
const terminalConfiguration: IConfigurationNode = {
3436
id: 'terminal',
3537
order: 100,
@@ -176,7 +178,7 @@ const terminalConfiguration: IConfigurationNode = {
176178
[TerminalSettingId.FontSize]: {
177179
description: localize('terminal.integrated.fontSize', "Controls the font size in pixels of the terminal."),
178180
type: 'number',
179-
default: isMacintosh ? 12 : 14,
181+
default: defaultTerminalFontSize,
180182
minimum: 6,
181183
maximum: 100
182184
},

src/vs/workbench/contrib/terminal/terminal.all.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal
1919
import 'vs/workbench/contrib/terminalContrib/find/browser/terminal.find.contribution';
2020
import 'vs/workbench/contrib/terminalContrib/highlight/browser/terminal.highlight.contribution';
2121
import 'vs/workbench/contrib/terminalContrib/links/browser/terminal.links.contribution';
22-
import 'vs/workbench/contrib/terminalContrib/mouseWheelZoom/browser/terminal.mouseWheelZoom.contribution';
22+
import 'vs/workbench/contrib/terminalContrib/zoom/browser/terminal.zoom.contribution';
2323
import 'vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminal.stickyScroll.contribution';
2424
import 'vs/workbench/contrib/terminalContrib/quickFix/browser/terminal.quickFix.contribution';
2525
import 'vs/workbench/contrib/terminalContrib/typeAhead/browser/terminal.typeAhead.contribution';
Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ import { TerminalSettingId } from 'vs/platform/terminal/common/terminal';
1313
import { IDetachedTerminalInstance, ITerminalContribution, ITerminalInstance, IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
1414
import { registerTerminalContribution } from 'vs/workbench/contrib/terminal/browser/terminalExtensions';
1515
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
16-
import { ITerminalProcessInfo, ITerminalProcessManager } from 'vs/workbench/contrib/terminal/common/terminal';
16+
import { ITerminalProcessInfo, ITerminalProcessManager, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
1717
import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/widgets/widgetManager';
18+
import { registerTerminalAction } from 'vs/workbench/contrib/terminal/browser/terminalActions';
19+
import { localize2 } from 'vs/nls';
20+
import { isNumber } from 'vs/base/common/types';
21+
import { defaultTerminalFontSize } from 'vs/workbench/contrib/terminal/common/terminalConfiguration';
1822

1923
class TerminalMouseWheelZoomContribution extends Disposable implements ITerminalContribution {
2024
static readonly ID = 'terminal.mouseWheelZoom';
@@ -69,7 +73,7 @@ class TerminalMouseWheelZoomContribution extends Disposable implements ITerminal
6973
raw.attachCustomWheelEventHandler((e: WheelEvent) => {
7074
const browserEvent = e as any as IMouseWheelEvent;
7175
if (classifier.isPhysicalMouseWheel()) {
72-
if (hasMouseWheelZoomModifiers(browserEvent)) {
76+
if (this._hasMouseWheelZoomModifiers(browserEvent)) {
7377
const delta = browserEvent.deltaY > 0 ? -1 : 1;
7478
this._configurationService.updateValue(TerminalSettingId.FontSize, this._getConfigFontSize() + delta);
7579
// EditorZoom.setZoomLevel(zoomLevel + delta);
@@ -84,7 +88,7 @@ class TerminalMouseWheelZoomContribution extends Disposable implements ITerminal
8488
if (Date.now() - prevMouseWheelTime > 50) {
8589
// reset if more than 50ms have passed
8690
gestureStartFontSize = this._getConfigFontSize();
87-
gestureHasZoomModifiers = hasMouseWheelZoomModifiers(browserEvent);
91+
gestureHasZoomModifiers = this._hasMouseWheelZoomModifiers(browserEvent);
8892
gestureAccumulatedDelta = 0;
8993
}
9094

@@ -106,16 +110,49 @@ class TerminalMouseWheelZoomContribution extends Disposable implements ITerminal
106110
});
107111
this._listener.value = toDisposable(() => raw.attachCustomWheelEventHandler(() => true));
108112
}
113+
114+
private _hasMouseWheelZoomModifiers(browserEvent: IMouseWheelEvent): boolean {
115+
return (
116+
isMacintosh
117+
// on macOS we support cmd + two fingers scroll (`metaKey` set)
118+
// and also the two fingers pinch gesture (`ctrKey` set)
119+
? ((browserEvent.metaKey || browserEvent.ctrlKey) && !browserEvent.shiftKey && !browserEvent.altKey)
120+
: (browserEvent.ctrlKey && !browserEvent.metaKey && !browserEvent.shiftKey && !browserEvent.altKey)
121+
);
122+
}
109123
}
110124

111125
registerTerminalContribution(TerminalMouseWheelZoomContribution.ID, TerminalMouseWheelZoomContribution, true);
112126

113-
function hasMouseWheelZoomModifiers(browserEvent: IMouseWheelEvent): boolean {
114-
return (
115-
isMacintosh
116-
// on macOS we support cmd + two fingers scroll (`metaKey` set)
117-
// and also the two fingers pinch gesture (`ctrKey` set)
118-
? ((browserEvent.metaKey || browserEvent.ctrlKey) && !browserEvent.shiftKey && !browserEvent.altKey)
119-
: (browserEvent.ctrlKey && !browserEvent.metaKey && !browserEvent.shiftKey && !browserEvent.altKey)
120-
);
121-
}
127+
registerTerminalAction({
128+
id: TerminalCommandId.FontZoomIn,
129+
title: localize2('fontZoomIn', 'Increase Font Size'),
130+
run: async (c, accessor) => {
131+
const configurationService = accessor.get(IConfigurationService);
132+
const value = configurationService.getValue(TerminalSettingId.FontSize);
133+
if (isNumber(value)) {
134+
await configurationService.updateValue(TerminalSettingId.FontSize, value + 1);
135+
}
136+
}
137+
});
138+
139+
registerTerminalAction({
140+
id: TerminalCommandId.FontZoomOut,
141+
title: localize2('fontZoomOut', 'Decrease Font Size'),
142+
run: async (c, accessor) => {
143+
const configurationService = accessor.get(IConfigurationService);
144+
const value = configurationService.getValue(TerminalSettingId.FontSize);
145+
if (isNumber(value)) {
146+
await configurationService.updateValue(TerminalSettingId.FontSize, value - 1);
147+
}
148+
}
149+
});
150+
151+
registerTerminalAction({
152+
id: TerminalCommandId.FontZoomReset,
153+
title: localize2('fontZoomReset', 'Reset Font Size'),
154+
run: async (c, accessor) => {
155+
const configurationService = accessor.get(IConfigurationService);
156+
await configurationService.updateValue(TerminalSettingId.FontSize, defaultTerminalFontSize);
157+
}
158+
});

0 commit comments

Comments
 (0)