mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Add onMultipleOptionChange
This commit is contained in:
@@ -27,6 +27,8 @@ export class CharSizeService extends Disposable implements ICharSizeService {
|
||||
) {
|
||||
super();
|
||||
this._measureStrategy = new DomMeasureStrategy(document, parentElement, this._optionsService);
|
||||
// TODO: ...
|
||||
// this.register(this._optionsService.onSpecificOptionChange(
|
||||
}
|
||||
|
||||
public measure(): void {
|
||||
|
||||
@@ -129,6 +129,14 @@ export class MockOptionsService implements IOptionsService {
|
||||
}
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
public onMultipleOptionChange(keys: (keyof ITerminalOptions)[], listener: () => any): IDisposable {
|
||||
return this.onOptionChange(eventKey => {
|
||||
if (keys.indexOf(eventKey) !== -1) {
|
||||
listener();
|
||||
}
|
||||
});
|
||||
}
|
||||
public setOptions(options: ITerminalOptions): void {
|
||||
for (const key of Object.keys(options)) {
|
||||
this.options[key] = options[key];
|
||||
|
||||
@@ -112,4 +112,39 @@ describe('OptionsService', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('onSpecificOptionChange', () => {
|
||||
let service: OptionsService;
|
||||
beforeEach(() => {
|
||||
service = new OptionsService({});
|
||||
});
|
||||
it('should fire only on a specific option change', async () => {
|
||||
await new Promise<void>(r => {
|
||||
service.onSpecificOptionChange('scrollback', e => {
|
||||
assert.strictEqual(e, 20);
|
||||
r();
|
||||
});
|
||||
service.options.cursorWidth = 10;
|
||||
service.options.scrollback = 20;
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('onMultipleOptionChange', () => {
|
||||
let service: OptionsService;
|
||||
beforeEach(() => {
|
||||
service = new OptionsService({});
|
||||
});
|
||||
it('should fire only for specific options', async () => {
|
||||
await new Promise<void>(r => {
|
||||
let called = false;
|
||||
service.onMultipleOptionChange(['scrollback'], () => {
|
||||
called = true;
|
||||
});
|
||||
service.options.cursorWidth = 10;
|
||||
assert.notOk(called);
|
||||
service.options.scrollback = 20;
|
||||
assert.ok(called);
|
||||
r();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,6 +91,15 @@ export class OptionsService extends Disposable implements IOptionsService {
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
public onMultipleOptionChange(keys: (keyof ITerminalOptions)[], listener: () => any): IDisposable {
|
||||
return this.onOptionChange(eventKey => {
|
||||
if (keys.indexOf(eventKey) !== -1) {
|
||||
listener();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _setupOptions(): void {
|
||||
const getter = (propName: string): any => {
|
||||
if (!(propName in DEFAULT_OPTIONS)) {
|
||||
|
||||
@@ -201,6 +201,14 @@ export interface IOptionsService {
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
onSpecificOptionChange<T extends keyof ITerminalOptions>(key: T, listener: (arg1: Required<ITerminalOptions>[T]) => any): IDisposable;
|
||||
|
||||
/**
|
||||
* Adds an event listener for when a set of specific options change, this is a convenience method
|
||||
* that is preferred over {@link onOptionChange} when multiple options are being listened to and
|
||||
* handled the same way.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
onMultipleOptionChange(keys: (keyof ITerminalOptions)[], listener: () => any): IDisposable;
|
||||
}
|
||||
|
||||
export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number;
|
||||
|
||||
Reference in New Issue
Block a user