提交 ad7cbfda 编写于 作者: M Matt Bierner

Use toDisposable in more places in editor

上级 f1e05055
......@@ -13,7 +13,7 @@ import { Event, Emitter } from 'vs/base/common/event';
import { ITextModel } from 'vs/editor/common/model';
import { onUnexpectedError } from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { DEFAULT_WORD_REGEXP, ensureValidWordDefinition } from 'vs/editor/common/model/wordHelper';
import { createScopedLineTokens } from 'vs/editor/common/modes/supports';
import { LineTokens } from 'vs/editor/common/core/lineTokens';
......@@ -189,14 +189,12 @@ export class LanguageConfigurationRegistryImpl {
let current = new RichEditSupport(languageIdentifier, previous, configuration);
this._entries[languageIdentifier.id] = current;
this._onDidChange.fire({ languageIdentifier });
return {
dispose: () => {
if (this._entries[languageIdentifier.id] === current) {
this._entries[languageIdentifier.id] = previous;
this._onDidChange.fire({ languageIdentifier });
}
return toDisposable(() => {
if (this._entries[languageIdentifier.id] === current) {
this._entries[languageIdentifier.id] = previous;
this._onDidChange.fire({ languageIdentifier });
}
};
});
}
private _getRichEditSupport(languageId: LanguageId): RichEditSupport {
......
......@@ -6,7 +6,7 @@
'use strict';
import { Event, Emitter } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { ITextModel } from 'vs/editor/common/model';
import { LanguageSelector, score } from 'vs/editor/common/modes/languageSelector';
import { shouldSynchronizeModel } from 'vs/editor/common/services/modelService';
......@@ -54,19 +54,17 @@ export default class LanguageFeatureRegistry<T> {
this._lastCandidate = undefined;
this._onDidChange.fire(this._entries.length);
return {
dispose: () => {
if (entry) {
let idx = this._entries.indexOf(entry);
if (idx >= 0) {
this._entries.splice(idx, 1);
this._lastCandidate = undefined;
this._onDidChange.fire(this._entries.length);
entry = undefined;
}
return toDisposable(() => {
if (entry) {
let idx = this._entries.indexOf(entry);
if (idx >= 0) {
this._entries.splice(idx, 1);
this._lastCandidate = undefined;
this._onDidChange.fire(this._entries.length);
entry = undefined;
}
}
};
});
}
has(model: ITextModel): boolean {
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { ColorId, ITokenizationRegistry, ITokenizationSupport, ITokenizationSupportChangedEvent } from 'vs/editor/common/modes';
import { Color } from 'vs/base/common/color';
......@@ -33,15 +33,13 @@ export class TokenizationRegistryImpl implements ITokenizationRegistry {
public register(language: string, support: ITokenizationSupport): IDisposable {
this._map[language] = support;
this.fire([language]);
return {
dispose: () => {
if (this._map[language] !== support) {
return;
}
delete this._map[language];
this.fire([language]);
return toDisposable(() => {
if (this._map[language] !== support) {
return;
}
};
delete this._map[language];
this.fire([language]);
});
}
public get(language: string): ITokenizationSupport {
......
......@@ -5,7 +5,7 @@
'use strict';
import { IntervalTimer, ShallowCancelThenPromise, wireCancellationToken } from 'vs/base/common/async';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Disposable, IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { SimpleWorkerClient, logOnceWebWorkerWarning } from 'vs/base/common/worker/simpleWorker';
......@@ -285,11 +285,9 @@ class EditorModelManager extends Disposable {
toDispose.push(model.onWillDispose(() => {
this._stopModelSync(modelUrl);
}));
toDispose.push({
dispose: () => {
this._proxy.acceptRemovedModel(modelUrl);
}
});
toDispose.push(toDisposable(() => {
this._proxy.acceptRemovedModel(modelUrl);
}));
this._syncedModels[modelUrl] = toDispose;
}
......
......@@ -9,7 +9,7 @@ import { Selection } from 'vs/editor/common/core/selection';
import { ScrollEvent } from 'vs/base/common/scrollable';
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
import * as errors from 'vs/base/common/errors';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { IDisposable, Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { ScrollType } from 'vs/editor/common/editorCommon';
export const enum ViewEventType {
......@@ -354,17 +354,15 @@ export class ViewEventEmitter extends Disposable {
public addEventListener(listener: (events: ViewEvent[]) => void): IDisposable {
this._listeners.push(listener);
return {
dispose: () => {
let listeners = this._listeners;
for (let i = 0, len = listeners.length; i < len; i++) {
if (listeners[i] === listener) {
listeners.splice(i, 1);
break;
}
return toDisposable(() => {
let listeners = this._listeners;
for (let i = 0, len = listeners.length; i < len; i++) {
if (listeners[i] === listener) {
listeners.splice(i, 1);
break;
}
}
};
});
}
}
......
......@@ -5,20 +5,20 @@
'use strict';
import { RunOnceScheduler, CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
import { CancelablePromise, createCancelablePromise, RunOnceScheduler } from 'vs/base/common/async';
import { onUnexpectedError } from 'vs/base/common/errors';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ICommandService } from 'vs/platform/commands/common/commands';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { CodeLensProviderRegistry, ICodeLensSymbol } from 'vs/editor/common/modes';
import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { StableEditorScrollState } from 'vs/editor/browser/core/editorState';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { ICodeLensData, getCodeLensData } from './codelens';
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
import { CodeLens, CodeLensHelper } from 'vs/editor/contrib/codelens/codelensWidget';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IModelDecorationsChangeAccessor } from 'vs/editor/common/model';
import { CodeLensProviderRegistry, ICodeLensSymbol } from 'vs/editor/common/modes';
import { CodeLens, CodeLensHelper } from 'vs/editor/contrib/codelens/codelensWidget';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { StableEditorScrollState } from 'vs/editor/browser/core/editorState';
import { getCodeLensData, ICodeLensData } from './codelens';
export class CodeLensContribution implements editorCommon.IEditorContribution {
......@@ -167,22 +167,20 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
this._localToDispose.push(this._editor.onDidLayoutChange(e => {
this._detectVisibleLenses.schedule();
}));
this._localToDispose.push({
dispose: () => {
if (this._editor.getModel()) {
const scrollState = StableEditorScrollState.capture(this._editor);
this._editor.changeDecorations((changeAccessor) => {
this._editor.changeViewZones((accessor) => {
this._disposeAllLenses(changeAccessor, accessor);
});
this._localToDispose.push(toDisposable(() => {
if (this._editor.getModel()) {
const scrollState = StableEditorScrollState.capture(this._editor);
this._editor.changeDecorations((changeAccessor) => {
this._editor.changeViewZones((accessor) => {
this._disposeAllLenses(changeAccessor, accessor);
});
scrollState.restore(this._editor);
} else {
// No accessors available
this._disposeAllLenses(null, null);
}
});
scrollState.restore(this._editor);
} else {
// No accessors available
this._disposeAllLenses(null, null);
}
});
}));
scheduler.schedule();
}
......
......@@ -24,7 +24,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { ITextModelService, ITextModelContentProvider, ITextEditorModel } from 'vs/editor/common/services/resolverService';
import { IDisposable, IReference, ImmortalReference, combinedDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, IReference, ImmortalReference, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle';
import * as dom from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeybindingsRegistry, IKeybindingItem } from 'vs/platform/keybinding/common/keybindingsRegistry';
......@@ -230,11 +230,9 @@ export class StandaloneCommandService implements ICommandService {
public addCommand(command: ICommand): IDisposable {
const { id } = command;
this._dynamicCommands[id] = command;
return {
dispose: () => {
delete this._dynamicCommands[id];
}
};
return toDisposable(() => {
delete this._dynamicCommands[id];
});
}
public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
......@@ -289,18 +287,16 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
weight2: 0
});
toDispose.push({
dispose: () => {
for (let i = 0; i < this._dynamicKeybindings.length; i++) {
let kb = this._dynamicKeybindings[i];
if (kb.command === commandId) {
this._dynamicKeybindings.splice(i, 1);
this.updateResolver({ source: KeybindingSource.Default });
return;
}
toDispose.push(toDisposable(() => {
for (let i = 0; i < this._dynamicKeybindings.length; i++) {
let kb = this._dynamicKeybindings[i];
if (kb.command === commandId) {
this._dynamicKeybindings.splice(i, 1);
this.updateResolver({ source: KeybindingSource.Default });
return;
}
}
});
}));
let commandService = this._commandService;
if (commandService instanceof StandaloneCommandService) {
......
......@@ -5,7 +5,7 @@
'use strict';
import { Disposable, IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
import { Disposable, IDisposable, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -272,11 +272,9 @@ export class StandaloneCodeEditor extends CodeEditorWidget implements IStandalon
// Store it under the original id, such that trigger with the original id will work
this._actions[id] = internalAction;
toDispose.push({
dispose: () => {
delete this._actions[id];
}
});
toDispose.push(toDisposable(() => {
delete this._actions[id];
}));
return combinedDisposable(toDispose);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册