mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Merge pull request #2485 from eamodio/feature/scroll-sensitivity
Adds scrollSensitivity option for scrolling speed
This commit is contained in:
+2
-2
@@ -254,7 +254,7 @@ function initOptions(term: TerminalType): void {
|
||||
});
|
||||
html += '</div><div class="option-group">';
|
||||
numberOptions.forEach(o => {
|
||||
html += `<div class="option"><label>${o} <input id="opt-${o}" type="number" value="${term.getOption(o)}" step="${o === 'lineHeight' ? '0.1' : '1'}"/></label></div>`;
|
||||
html += `<div class="option"><label>${o} <input id="opt-${o}" type="number" value="${term.getOption(o)}" step="${o === 'lineHeight' || o === 'scrollSensitivity' ? '0.1' : '1'}"/></label></div>`;
|
||||
});
|
||||
html += '</div><div class="option-group">';
|
||||
Object.keys(stringOptions).forEach(o => {
|
||||
@@ -283,7 +283,7 @@ function initOptions(term: TerminalType): void {
|
||||
console.log('change', o, input.value);
|
||||
if (o === 'cols' || o === 'rows') {
|
||||
updateTerminalSize();
|
||||
} else if (o === 'lineHeight') {
|
||||
} else if (o === 'lineHeight' || o === 'scrollSensitivity') {
|
||||
term.setOption(o, parseFloat(input.value));
|
||||
updateTerminalSize();
|
||||
} else {
|
||||
|
||||
@@ -198,7 +198,7 @@ export class Viewport extends Disposable implements IViewport {
|
||||
}
|
||||
|
||||
// Fallback to WheelEvent.DOM_DELTA_PIXEL
|
||||
let amount = this._applyFastScrollModifier(ev.deltaY, ev);
|
||||
let amount = this._applyScrollModifier(ev.deltaY, ev);
|
||||
if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
|
||||
amount *= this._currentRowHeight;
|
||||
} else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
|
||||
@@ -219,7 +219,7 @@ export class Viewport extends Disposable implements IViewport {
|
||||
}
|
||||
|
||||
// Fallback to WheelEvent.DOM_DELTA_LINE
|
||||
let amount = this._applyFastScrollModifier(ev.deltaY, ev);
|
||||
let amount = this._applyScrollModifier(ev.deltaY, ev);
|
||||
if (ev.deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
|
||||
amount /= this._currentRowHeight + 0.0; // Prevent integer division
|
||||
this._wheelPartialScroll += amount;
|
||||
@@ -231,15 +231,16 @@ export class Viewport extends Disposable implements IViewport {
|
||||
return amount;
|
||||
}
|
||||
|
||||
private _applyFastScrollModifier(amount: number, ev: WheelEvent): number {
|
||||
private _applyScrollModifier(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 * Math.max(1, this._optionsService.options.fastScrollSensitivity);
|
||||
return amount * this._optionsService.options.fastScrollSensitivity;
|
||||
}
|
||||
return amount;
|
||||
|
||||
return amount * this._optionsService.options.scrollSensitivity;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({
|
||||
letterSpacing: 0,
|
||||
logLevel: 'info',
|
||||
scrollback: 1000,
|
||||
scrollSensitivity: 1,
|
||||
screenReaderMode: false,
|
||||
macOptionIsMeta: false,
|
||||
macOptionClickForcesSelection: false,
|
||||
@@ -121,6 +122,12 @@ export class OptionsService implements IOptionsService {
|
||||
throw new Error(`${key} cannot be less than 0, value: ${value}`);
|
||||
}
|
||||
break;
|
||||
case 'fastScrollSensitivity':
|
||||
case 'scrollSensitivity':
|
||||
if (value <= 0) {
|
||||
throw new Error(`${key} cannot be less than or equal to 0, value: ${value}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -196,6 +196,7 @@ export interface IPartialTerminalOptions {
|
||||
rows?: number;
|
||||
screenReaderMode?: boolean;
|
||||
scrollback?: number;
|
||||
scrollSensitivity?: number;
|
||||
tabStopWidth?: number;
|
||||
theme?: ITheme;
|
||||
windowsMode?: boolean;
|
||||
@@ -227,6 +228,7 @@ export interface ITerminalOptions {
|
||||
rows: number;
|
||||
screenReaderMode: boolean;
|
||||
scrollback: number;
|
||||
scrollSensitivity: number;
|
||||
tabStopWidth: number;
|
||||
theme: ITheme;
|
||||
windowsMode: boolean;
|
||||
|
||||
Vendored
+5
@@ -183,6 +183,11 @@ declare module 'xterm' {
|
||||
*/
|
||||
scrollback?: number;
|
||||
|
||||
/**
|
||||
* The scrolling speed multiplier used for adjusting normal scrolling speed.
|
||||
*/
|
||||
scrollSensitivity?: number;
|
||||
|
||||
/**
|
||||
* The size of tab stops in the terminal.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user