Avoid passing circular callback into CoreService ctor
This commit is contained in:
@@ -13,7 +13,6 @@ describe('CoreService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
coreService = new CoreService(
|
||||
() => {},
|
||||
new MockBufferService(80, 30),
|
||||
new MockLogService(),
|
||||
new MockOptionsService());
|
||||
|
||||
@@ -31,26 +31,21 @@ export class CoreService extends Disposable implements ICoreService {
|
||||
public modes: IModes;
|
||||
public decPrivateModes: IDecPrivateModes;
|
||||
|
||||
// Circular dependency, this must be unset or memory will leak after Terminal.dispose
|
||||
private _scrollToBottom: (() => void) | undefined;
|
||||
|
||||
private readonly _onData = this.register(new EventEmitter<string>());
|
||||
public readonly onData = this._onData.event;
|
||||
private readonly _onUserInput = this.register(new EventEmitter<void>());
|
||||
public readonly onUserInput = this._onUserInput.event;
|
||||
private readonly _onBinary = this.register(new EventEmitter<string>());
|
||||
public readonly onBinary = this._onBinary.event;
|
||||
private readonly _onRequestScrollToBottom = this.register(new EventEmitter<void>());
|
||||
public readonly onRequestScrollToBottom = this._onRequestScrollToBottom.event;
|
||||
|
||||
constructor(
|
||||
// TODO: Move this into a service
|
||||
scrollToBottom: () => void,
|
||||
@IBufferService private readonly _bufferService: IBufferService,
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@IOptionsService private readonly _optionsService: IOptionsService
|
||||
) {
|
||||
super();
|
||||
this._scrollToBottom = scrollToBottom;
|
||||
this.register({ dispose: () => this._scrollToBottom = undefined });
|
||||
this.modes = clone(DEFAULT_MODES);
|
||||
this.decPrivateModes = clone(DEFAULT_DEC_PRIVATE_MODES);
|
||||
}
|
||||
@@ -69,7 +64,7 @@ export class CoreService extends Disposable implements ICoreService {
|
||||
// Input is being sent to the terminal, the terminal should focus the prompt.
|
||||
const buffer = this._bufferService.buffer;
|
||||
if (buffer.ybase !== buffer.ydisp) {
|
||||
this._scrollToBottom!();
|
||||
this._onRequestScrollToBottom.fire();
|
||||
}
|
||||
|
||||
// Fire onUserInput so listeners can react as well (eg. clear selection)
|
||||
|
||||
@@ -79,6 +79,7 @@ export interface ICoreService {
|
||||
readonly onData: IEvent<string>;
|
||||
readonly onUserInput: IEvent<void>;
|
||||
readonly onBinary: IEvent<string>;
|
||||
readonly onRequestScrollToBottom: IEvent<void>;
|
||||
|
||||
reset(): void;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user