mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 13:29:44 +00:00
Use disposableStore for activeEditorListeners
This commit is contained in:
parent
47ce882e77
commit
2aa587600d
|
@ -13,7 +13,7 @@ import { IHistoryService } from 'vs/workbench/services/history/common/history';
|
|||
import { FileChangesEvent, IFileService, FileChangeType, FILES_EXCLUDE_CONFIG } from 'vs/platform/files/common/files';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, dispose, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
|
@ -105,11 +105,11 @@ export class HistoryService extends Disposable implements IHistoryService {
|
|||
private static readonly MAX_STACK_ITEMS = 50;
|
||||
private static readonly MAX_RECENTLY_CLOSED_EDITORS = 20;
|
||||
|
||||
private activeEditorListeners: IDisposable[];
|
||||
private readonly activeEditorListeners = this._register(new DisposableStore());
|
||||
private lastActiveEditor?: IEditorIdentifier;
|
||||
|
||||
private editorHistoryListeners: Map<EditorInput, IDisposable[]> = new Map();
|
||||
private editorStackListeners: Map<EditorInput, IDisposable[]> = new Map();
|
||||
private readonly editorHistoryListeners: Map<EditorInput, IDisposable[]> = new Map();
|
||||
private readonly editorStackListeners: Map<EditorInput, IDisposable[]> = new Map();
|
||||
|
||||
private stack: IStackEntry[];
|
||||
private index: number;
|
||||
|
@ -144,8 +144,6 @@ export class HistoryService extends Disposable implements IHistoryService {
|
|||
) {
|
||||
super();
|
||||
|
||||
this.activeEditorListeners = [];
|
||||
|
||||
this.canNavigateBackContextKey = (new RawContextKey<boolean>('canNavigateBack', false)).bindTo(this.contextKeyService);
|
||||
this.canNavigateForwardContextKey = (new RawContextKey<boolean>('canNavigateForward', false)).bindTo(this.contextKeyService);
|
||||
this.canNavigateToLastEditLocationContextKey = (new RawContextKey<boolean>('canNavigateToLastEditLocation', false)).bindTo(this.contextKeyService);
|
||||
|
@ -198,8 +196,7 @@ export class HistoryService extends Disposable implements IHistoryService {
|
|||
this.lastActiveEditor = activeControl && activeControl.input && activeControl.group ? { editor: activeControl.input, groupId: activeControl.group.id } : undefined;
|
||||
|
||||
// Dispose old listeners
|
||||
dispose(this.activeEditorListeners);
|
||||
this.activeEditorListeners = [];
|
||||
this.activeEditorListeners.clear();
|
||||
|
||||
// Propagate to history
|
||||
this.handleActiveEditorChange(activeControl);
|
||||
|
@ -212,14 +209,14 @@ export class HistoryService extends Disposable implements IHistoryService {
|
|||
// Debounce the event with a timeout of 0ms so that multiple calls to
|
||||
// editor.setSelection() are folded into one. We do not want to record
|
||||
// subsequent history navigations for such API calls.
|
||||
this.activeEditorListeners.push(Event.debounce(activeTextEditorWidget.onDidChangeCursorPosition, (last, event) => event, 0)((event => {
|
||||
this.activeEditorListeners.add(Event.debounce(activeTextEditorWidget.onDidChangeCursorPosition, (last, event) => event, 0)((event => {
|
||||
this.handleEditorSelectionChangeEvent(activeControl, event);
|
||||
})));
|
||||
|
||||
// Track the last edit location by tracking model content change events
|
||||
// Use a debouncer to make sure to capture the correct cursor position
|
||||
// after the model content has changed.
|
||||
this.activeEditorListeners.push(Event.debounce(activeTextEditorWidget.onDidChangeModelContent, (last, event) => event, 0)((event => this.rememberLastEditLocation(activeEditor!, activeTextEditorWidget))));
|
||||
this.activeEditorListeners.add(Event.debounce(activeTextEditorWidget.onDidChangeModelContent, (last, event) => event, 0)((event => this.rememberLastEditLocation(activeEditor!, activeTextEditorWidget))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue