From 73a17cfacba896d8ffe750284d17e7a6338ad871 Mon Sep 17 00:00:00 2001 From: Corentin Surquin Date: Sat, 10 Aug 2019 01:07:43 +0200 Subject: [PATCH 1/5] Support fast scrolling using a modifier key --- demo/client.ts | 1 + src/browser/Viewport.ts | 28 +++++++++++++++++++++++++-- src/common/services/OptionsService.ts | 2 ++ src/common/services/Services.ts | 4 ++++ typings/xterm.d.ts | 10 ++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/demo/client.ts b/demo/client.ts index 040292e4..88d32c0b 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 9625588d..94bb0fbf 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 9a5d2151..bde40c11 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 1af55e9a..184a6f9a 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 d9e28b26..97bc4cf0 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. */ From a353a8cffe45dcba65fde15554c758b5fb6fe509 Mon Sep 17 00:00:00 2001 From: Corentin Surquin Date: Sat, 10 Aug 2019 01:23:45 +0200 Subject: [PATCH 2/5] Allow to disable fast scrolling --- demo/client.ts | 2 +- src/common/services/Services.ts | 2 +- typings/xterm.d.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/demo/client.ts b/demo/client.ts index 88d32c0b..c6f66dc0 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -228,7 +228,7 @@ function initOptions(term: TerminalType): void { bellSound: null, bellStyle: ['none', 'sound'], cursorStyle: ['block', 'underline', 'bar'], - fastScrollModifier: ['alt', 'ctrl', 'shift'], + fastScrollModifier: ['alt', 'ctrl', 'shift', undefined], 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/common/services/Services.ts b/src/common/services/Services.ts index 184a6f9a..8f4eb39e 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -180,7 +180,7 @@ export interface ITerminalOptions { cursorStyle: 'block' | 'underline' | 'bar'; disableStdin: boolean; drawBoldTextInBrightColors: boolean; - fastScrollModifier: 'alt' | 'ctrl' | 'shift'; + fastScrollModifier: 'alt' | 'ctrl' | 'shift' | undefined; fastScrollSensitivity: number; fontSize: number; fontFamily: string; diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 97bc4cf0..9ea85d07 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -85,7 +85,7 @@ declare module 'xterm' { /** * The modifier key hold to multiply scroll speed. */ - fastScrollModifier?: 'alt' | 'ctrl' | 'shift'; + fastScrollModifier?: 'alt' | 'ctrl' | 'shift' | undefined; /** * The scroll speed multiplier used for fast scrolling. From e76b8f86b5cfe434c0586d46238198d7b5ed7769 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 15 Oct 2019 16:21:17 -0700 Subject: [PATCH 3/5] Pull modifier code into helper, apply to lines scrolled --- src/browser/Viewport.ts | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/browser/Viewport.ts b/src/browser/Viewport.ts index 8747297a..bea5d99d 100644 --- a/src/browser/Viewport.ts +++ b/src/browser/Viewport.ts @@ -191,31 +191,9 @@ 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 * multiplier; + let amount = this._applyFastScrollModifier(ev.deltaY, ev); if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) { amount *= this._currentRowHeight; } else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) { @@ -236,7 +214,7 @@ export class Viewport extends Disposable implements IViewport { } // Fallback to WheelEvent.DOM_DELTA_LINE - let amount = ev.deltaY; + let amount = this._applyFastScrollModifier(ev.deltaY, ev); if (ev.deltaMode === WheelEvent.DOM_DELTA_PIXEL) { amount /= this._currentRowHeight + 0.0; // Prevent integer division this._wheelPartialScroll += amount; @@ -248,6 +226,17 @@ export class Viewport extends Disposable implements IViewport { return amount; } + private _applyFastScrollModifier(amount: number, ev: WheelEvent): number { + const modifier = this._optionsService.options.fastScrollModifier; + // Multiply the scroll speed when the modifier is down + if ((modifier === 'alt' && ev.altKey) || + (modifier === 'ctrl' && ev.ctrlKey) || + (modifier === 'shift' && ev.shiftKey)) { + return amount * this._optionsService.options.fastScrollSensitivity; + } + return amount; + } + /** * Handles the touchstart event, recording the touch occurred. * @param ev The touch event. From 9fdb674f2056258dfe784c9afd7e7d94cce8318e Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 15 Oct 2019 16:22:09 -0700 Subject: [PATCH 4/5] Use min of 1 for fast scroll --- src/browser/Viewport.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/Viewport.ts b/src/browser/Viewport.ts index bea5d99d..063fbc66 100644 --- a/src/browser/Viewport.ts +++ b/src/browser/Viewport.ts @@ -232,7 +232,7 @@ export class Viewport extends Disposable implements IViewport { if ((modifier === 'alt' && ev.altKey) || (modifier === 'ctrl' && ev.ctrlKey) || (modifier === 'shift' && ev.shiftKey)) { - return amount * this._optionsService.options.fastScrollSensitivity; + return amount * Math.max(1, this._optionsService.options.fastScrollSensitivity); } return amount; } From 4f8cda9f3a477e584eb04ee0053efd214df0e27a Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 15 Oct 2019 16:22:41 -0700 Subject: [PATCH 5/5] Remove bad whitespace --- src/browser/Viewport.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/browser/Viewport.ts b/src/browser/Viewport.ts index 063fbc66..d200ef8c 100644 --- a/src/browser/Viewport.ts +++ b/src/browser/Viewport.ts @@ -191,7 +191,6 @@ export class Viewport extends Disposable implements IViewport { return 0; } - // Fallback to WheelEvent.DOM_DELTA_PIXEL let amount = this._applyFastScrollModifier(ev.deltaY, ev); if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {