diff --git a/demo/client.ts b/demo/client.ts index 040292e4a..88d32c0b7 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -228,6 +228,7 @@ function initOptions(term: TerminalType): void { bellSound: null, bellStyle: ['none', 'sound'], cursorStyle: ['block', 'underline', 'bar'], + fastScrollModifier: ['alt', 'ctrl', 'shift'], fontFamily: null, fontWeight: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'], fontWeightBold: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'], diff --git a/src/browser/Viewport.ts b/src/browser/Viewport.ts index 9625588d5..94bb0fbff 100644 --- a/src/browser/Viewport.ts +++ b/src/browser/Viewport.ts @@ -7,7 +7,7 @@ import { Disposable } from 'common/Lifecycle'; import { addDisposableDomListener } from 'browser/Lifecycle'; import { IColorSet, IViewport } from 'browser/Types'; import { ICharSizeService, IRenderService } from 'browser/services/Services'; -import { IBufferService } from 'common/services/Services'; +import { IBufferService, IOptionsService } from 'common/services/Services'; const FALLBACK_SCROLL_BAR_WIDTH = 15; @@ -37,6 +37,7 @@ export class Viewport extends Disposable implements IViewport { private readonly _viewportElement: HTMLElement, private readonly _scrollArea: HTMLElement, @IBufferService private readonly _bufferService: IBufferService, + @IOptionsService private readonly _optionsService: IOptionsService, @ICharSizeService private readonly _charSizeService: ICharSizeService, @IRenderService private readonly _renderService: IRenderService ) { @@ -174,8 +175,31 @@ export class Viewport extends Disposable implements IViewport { return 0; } + const modifier = this._optionsService.options.fastScrollModifier; + const sensitivity = this._optionsService.options.fastScrollSensitivity; + + // Multiply the scroll speed when the modifier is down + let multiplier = 1; + switch (modifier) { + case 'alt': + if (ev.altKey) { + multiplier = sensitivity; + } + break; + case 'ctrl': + if (ev.ctrlKey) { + multiplier = sensitivity; + } + break; + case 'shift': + if (ev.shiftKey) { + multiplier = sensitivity; + } + break; + } + // Fallback to WheelEvent.DOM_DELTA_PIXEL - let amount = ev.deltaY; + let amount = ev.deltaY * multiplier; if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) { amount *= this._currentRowHeight; } else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) { diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index 9a5d2151d..bde40c115 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -23,6 +23,8 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({ bellSound: DEFAULT_BELL_SOUND, bellStyle: 'none', drawBoldTextInBrightColors: true, + fastScrollModifier: 'alt', + fastScrollSensitivity: 5, fontFamily: 'courier-new, courier, monospace', fontSize: 15, fontWeight: 'normal', diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 1af55e9ad..184a6f9ab 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -149,6 +149,8 @@ export interface IPartialTerminalOptions { cursorStyle?: 'block' | 'underline' | 'bar'; disableStdin?: boolean; drawBoldTextInBrightColors?: boolean; + fastScrollModifier?: 'alt' | 'ctrl' | 'shift'; + fastScrollSensitivity?: number; fontSize?: number; fontFamily?: string; fontWeight?: FontWeight; @@ -178,6 +180,8 @@ export interface ITerminalOptions { cursorStyle: 'block' | 'underline' | 'bar'; disableStdin: boolean; drawBoldTextInBrightColors: boolean; + fastScrollModifier: 'alt' | 'ctrl' | 'shift'; + fastScrollSensitivity: number; fontSize: number; fontFamily: string; fontWeight: FontWeight; diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index d9e28b265..97bc4cf01 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -82,6 +82,16 @@ declare module 'xterm' { */ drawBoldTextInBrightColors?: boolean; + /** + * The modifier key hold to multiply scroll speed. + */ + fastScrollModifier?: 'alt' | 'ctrl' | 'shift'; + + /** + * The scroll speed multiplier used for fast scrolling. + */ + fastScrollSensitivity?: number; + /** * The font size used to render text. */