Adopt MutableDisposable in SearchAddon
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
|
import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
|
||||||
import type { SearchAddon as ISearchApi } from '@xterm/addon-search';
|
import type { SearchAddon as ISearchApi } from '@xterm/addon-search';
|
||||||
import { EventEmitter } from 'common/EventEmitter';
|
import { EventEmitter } from 'common/EventEmitter';
|
||||||
import { Disposable, toDisposable, disposeArray, MutableDisposable } from 'common/Lifecycle';
|
import { Disposable, toDisposable, disposeArray, MutableDisposable, getDisposeArrayDisposable } from 'common/Lifecycle';
|
||||||
|
|
||||||
export interface ISearchOptions {
|
export interface ISearchOptions {
|
||||||
regex?: boolean;
|
regex?: boolean;
|
||||||
@@ -78,9 +78,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
|
|||||||
*/
|
*/
|
||||||
private _linesCache: LineCacheEntry[] | undefined;
|
private _linesCache: LineCacheEntry[] | undefined;
|
||||||
private _linesCacheTimeoutId = 0;
|
private _linesCacheTimeoutId = 0;
|
||||||
private _lineFeedListener: IDisposable | undefined;
|
private _linesCacheDisposables = new MutableDisposable();
|
||||||
private _cursorMoveListener: IDisposable | undefined;
|
|
||||||
private _resizeListener: IDisposable | undefined;
|
|
||||||
|
|
||||||
private readonly _onDidChangeResults = this.register(new EventEmitter<{ resultIndex: number, resultCount: number }>());
|
private readonly _onDidChangeResults = this.register(new EventEmitter<{ resultIndex: number, resultCount: number }>());
|
||||||
public readonly onDidChangeResults = this._onDidChangeResults.event;
|
public readonly onDidChangeResults = this._onDidChangeResults.event;
|
||||||
@@ -428,9 +426,11 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
|
|||||||
const terminal = this._terminal!;
|
const terminal = this._terminal!;
|
||||||
if (!this._linesCache) {
|
if (!this._linesCache) {
|
||||||
this._linesCache = new Array(terminal.buffer.active.length);
|
this._linesCache = new Array(terminal.buffer.active.length);
|
||||||
this._lineFeedListener = terminal.onLineFeed(() => this._destroyLinesCache());
|
this._linesCacheDisposables.value = getDisposeArrayDisposable([
|
||||||
this._cursorMoveListener = terminal.onCursorMove(() => this._destroyLinesCache());
|
terminal.onLineFeed(() => this._destroyLinesCache()),
|
||||||
this._resizeListener = terminal.onResize(() => this._destroyLinesCache());
|
terminal.onCursorMove(() => this._destroyLinesCache()),
|
||||||
|
terminal.onResize(() => this._destroyLinesCache())
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.clearTimeout(this._linesCacheTimeoutId);
|
window.clearTimeout(this._linesCacheTimeoutId);
|
||||||
@@ -439,18 +439,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
|
|||||||
|
|
||||||
private _destroyLinesCache(): void {
|
private _destroyLinesCache(): void {
|
||||||
this._linesCache = undefined;
|
this._linesCache = undefined;
|
||||||
if (this._cursorMoveListener) {
|
this._linesCacheDisposables.clear();
|
||||||
this._cursorMoveListener.dispose();
|
|
||||||
this._cursorMoveListener = undefined;
|
|
||||||
}
|
|
||||||
if (this._resizeListener) {
|
|
||||||
this._resizeListener.dispose();
|
|
||||||
this._resizeListener = undefined;
|
|
||||||
}
|
|
||||||
if (this._lineFeedListener) {
|
|
||||||
this._lineFeedListener.dispose();
|
|
||||||
this._lineFeedListener = undefined;
|
|
||||||
}
|
|
||||||
if (this._linesCacheTimeoutId) {
|
if (this._linesCacheTimeoutId) {
|
||||||
window.clearTimeout(this._linesCacheTimeoutId);
|
window.clearTimeout(this._linesCacheTimeoutId);
|
||||||
this._linesCacheTimeoutId = 0;
|
this._linesCacheTimeoutId = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user