diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index b823747dede642d9b768c5c00d13e9cd75ffd294..fd92e00b7784f8c155725381bf25f6e71f7da42a 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -99,12 +99,7 @@ class VisualEditorState { this._zonesMap = {}; // (2) Model decorations - if (this._decorations.length > 0) { - editor.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => { - changeAccessor.deltaDecorations(this._decorations, []); - }); - } - this._decorations = []; + this._decorations = editor.deltaDecorations(this._decorations, []); } public apply(editor: CodeEditor, overviewRuler: editorBrowser.IOverviewRuler, newDecorations: IEditorDiffDecorationsWithZones): void { diff --git a/src/vs/editor/contrib/colorPicker/colorDetector.ts b/src/vs/editor/contrib/colorPicker/colorDetector.ts index b839e90d2078a1e5958d6222e96416443eb48ce1..97fbb7b88520a546ca6b4b29469635ac042f0d80 100644 --- a/src/vs/editor/contrib/colorPicker/colorDetector.ts +++ b/src/vs/editor/contrib/colorPicker/colorDetector.ts @@ -16,6 +16,7 @@ import { ColorProviderRegistry } from 'vs/editor/common/modes'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { getColors, IColorData } from 'vs/editor/contrib/colorPicker/color'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { ModelDecorationOptions } from 'vs/editor/common/model/textModel'; const MAX_DECORATORS = 500; @@ -153,7 +154,7 @@ export class ColorDetector implements IEditorContribution { endLineNumber: c.colorInfo.range.endLineNumber, endColumn: c.colorInfo.range.endColumn }, - options: {} + options: ModelDecorationOptions.EMPTY })); this._decorationsIds = this._editor.deltaDecorations(this._decorationsIds, decorations); diff --git a/src/vs/editor/contrib/dnd/dnd.ts b/src/vs/editor/contrib/dnd/dnd.ts index 6cc7e1aced4edcea2353f3963a980f4532fb6c22..25a6ccf43635ba376ce397d6c2dfc687c463549e 100644 --- a/src/vs/editor/contrib/dnd/dnd.ts +++ b/src/vs/editor/contrib/dnd/dnd.ts @@ -173,22 +173,17 @@ export class DragAndDropController implements editorCommon.IEditorContribution { }); public showAt(position: Position): void { - this._editor.changeDecorations(changeAccessor => { - let newDecorations: IModelDeltaDecoration[] = []; - newDecorations.push({ - range: new Range(position.lineNumber, position.column, position.lineNumber, position.column), - options: DragAndDropController._DECORATION_OPTIONS - }); + let newDecorations: IModelDeltaDecoration[] = [{ + range: new Range(position.lineNumber, position.column, position.lineNumber, position.column), + options: DragAndDropController._DECORATION_OPTIONS + }]; - this._dndDecorationIds = changeAccessor.deltaDecorations(this._dndDecorationIds, newDecorations); - }); + this._dndDecorationIds = this._editor.deltaDecorations(this._dndDecorationIds, newDecorations); this._editor.revealPosition(position, editorCommon.ScrollType.Immediate); } private _removeDecoration(): void { - this._editor.changeDecorations(changeAccessor => { - changeAccessor.deltaDecorations(this._dndDecorationIds, []); - }); + this._dndDecorationIds = this._editor.deltaDecorations(this._dndDecorationIds, []); } private _hitContent(target: IMouseTarget): boolean { diff --git a/src/vs/editor/contrib/folding/foldingDecorations.ts b/src/vs/editor/contrib/folding/foldingDecorations.ts index fcc392cb18470f7e1d3827be7211db5ae3e1929a..17359b411fb3c5d6ce40af9a63b0572eb8c3f914 100644 --- a/src/vs/editor/contrib/folding/foldingDecorations.ts +++ b/src/vs/editor/contrib/folding/foldingDecorations.ts @@ -10,18 +10,18 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; export class FoldingDecorationProvider implements IDecorationProvider { - private COLLAPSED_VISUAL_DECORATION = ModelDecorationOptions.register({ + private static COLLAPSED_VISUAL_DECORATION = ModelDecorationOptions.register({ stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, afterContentClassName: 'inline-folded', linesDecorationsClassName: 'folding collapsed' }); - private EXPANDED_AUTO_HIDE_VISUAL_DECORATION = ModelDecorationOptions.register({ + private static EXPANDED_AUTO_HIDE_VISUAL_DECORATION = ModelDecorationOptions.register({ stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, linesDecorationsClassName: 'folding' }); - private EXPANDED_VISUAL_DECORATION = ModelDecorationOptions.register({ + private static EXPANDED_VISUAL_DECORATION = ModelDecorationOptions.register({ stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, linesDecorationsClassName: 'folding alwaysShowFoldIcons' }); @@ -33,11 +33,11 @@ export class FoldingDecorationProvider implements IDecorationProvider { getDecorationOption(isCollapsed: boolean): ModelDecorationOptions { if (isCollapsed) { - return this.COLLAPSED_VISUAL_DECORATION; + return FoldingDecorationProvider.COLLAPSED_VISUAL_DECORATION; } else if (this.autoHideFoldingControls) { - return this.EXPANDED_AUTO_HIDE_VISUAL_DECORATION; + return FoldingDecorationProvider.EXPANDED_AUTO_HIDE_VISUAL_DECORATION; } else { - return this.EXPANDED_VISUAL_DECORATION; + return FoldingDecorationProvider.EXPANDED_VISUAL_DECORATION; } } diff --git a/src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts b/src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts index 0d8c406b5e734c9c9ef41b795df71098d0ed3fdf..18548f6eccc5e93c9987a5c50a34e0dae65cb7f7 100644 --- a/src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts +++ b/src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts @@ -10,7 +10,6 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; -import { IModelDecorationsChangeAccessor } from 'vs/editor/common/model'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { registerEditorAction, ServicesAccessor, EditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { IInplaceReplaceSupportResult } from 'vs/editor/common/modes'; @@ -131,9 +130,7 @@ class InPlaceReplaceController implements IEditorContribution { this.decorationRemover.cancel(); this.decorationRemover = TPromise.timeout(350); this.decorationRemover.then(() => { - this.editor.changeDecorations((accessor: IModelDecorationsChangeAccessor) => { - this.decorationIds = accessor.deltaDecorations(this.decorationIds, []); - }); + this.decorationIds = this.editor.deltaDecorations(this.decorationIds, []); }); }); } diff --git a/src/vs/editor/contrib/links/links.ts b/src/vs/editor/contrib/links/links.ts index d62f77d70a410c7b88cbc1de432b1737c267f779..b981403915991f3ef0d12f4d959b9fe2eab3f076 100644 --- a/src/vs/editor/contrib/links/links.ts +++ b/src/vs/editor/contrib/links/links.ts @@ -251,32 +251,30 @@ class LinkDetector implements editorCommon.IEditorContribution { private updateDecorations(links: Link[]): void { const useMetaKey = (this.editor.getConfiguration().multiCursorModifier === 'altKey'); - this.editor.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => { - var oldDecorations: string[] = []; - let keys = Object.keys(this.currentOccurrences); - for (let i = 0, len = keys.length; i < len; i++) { - let decorationId = keys[i]; - let occurance = this.currentOccurrences[decorationId]; - oldDecorations.push(occurance.decorationId); - } + let oldDecorations: string[] = []; + let keys = Object.keys(this.currentOccurrences); + for (let i = 0, len = keys.length; i < len; i++) { + let decorationId = keys[i]; + let occurance = this.currentOccurrences[decorationId]; + oldDecorations.push(occurance.decorationId); + } - var newDecorations: IModelDeltaDecoration[] = []; - if (links) { - // Not sure why this is sometimes null - for (var i = 0; i < links.length; i++) { - newDecorations.push(LinkOccurrence.decoration(links[i], useMetaKey)); - } + let newDecorations: IModelDeltaDecoration[] = []; + if (links) { + // Not sure why this is sometimes null + for (let i = 0; i < links.length; i++) { + newDecorations.push(LinkOccurrence.decoration(links[i], useMetaKey)); } + } - var decorations = changeAccessor.deltaDecorations(oldDecorations, newDecorations); + let decorations = this.editor.deltaDecorations(oldDecorations, newDecorations); - this.currentOccurrences = {}; - this.activeLinkDecorationId = null; - for (let i = 0, len = decorations.length; i < len; i++) { - var occurance = new LinkOccurrence(links[i], decorations[i]); - this.currentOccurrences[occurance.decorationId] = occurance; - } - }); + this.currentOccurrences = {}; + this.activeLinkDecorationId = null; + for (let i = 0, len = decorations.length; i < len; i++) { + let occurance = new LinkOccurrence(links[i], decorations[i]); + this.currentOccurrences[occurance.decorationId] = occurance; + } } private _onEditorMouseMove(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent): void { diff --git a/src/vs/editor/contrib/multicursor/multicursor.ts b/src/vs/editor/contrib/multicursor/multicursor.ts index 6561c8b9ab663c4ff33e30be6cbadaa367cbac19..931c4f02404441303553204b018f8244b455bc1b 100644 --- a/src/vs/editor/contrib/multicursor/multicursor.ts +++ b/src/vs/editor/contrib/multicursor/multicursor.ts @@ -803,9 +803,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut this.state = state; if (!this.state) { - if (this.decorations.length > 0) { - this.decorations = this.editor.deltaDecorations(this.decorations, []); - } + this.decorations = this.editor.deltaDecorations(this.decorations, []); return; } diff --git a/src/vs/editor/contrib/referenceSearch/referencesWidget.ts b/src/vs/editor/contrib/referenceSearch/referencesWidget.ts index 125595fb2494ff52a538105e6f72e036e7863c91..d944550b9d1f6ae9cdc49e04c6fd3c6c6f1b1d07 100644 --- a/src/vs/editor/contrib/referenceSearch/referencesWidget.ts +++ b/src/vs/editor/contrib/referenceSearch/referencesWidget.ts @@ -84,28 +84,25 @@ class DecorationsManager implements IDisposable { private _addDecorations(reference: FileReferences): void { this._callOnModelChange.push(this._editor.getModel().onDidChangeDecorations((event) => this._onDecorationChanged())); - this._editor.changeDecorations(accessor => { + const newDecorations: IModelDeltaDecoration[] = []; + const newDecorationsActualIndex: number[] = []; - const newDecorations: IModelDeltaDecoration[] = []; - const newDecorationsActualIndex: number[] = []; - - for (let i = 0, len = reference.children.length; i < len; i++) { - let oneReference = reference.children[i]; - if (this._decorationIgnoreSet.has(oneReference.id)) { - continue; - } - newDecorations.push({ - range: oneReference.range, - options: DecorationsManager.DecorationOptions - }); - newDecorationsActualIndex.push(i); + for (let i = 0, len = reference.children.length; i < len; i++) { + let oneReference = reference.children[i]; + if (this._decorationIgnoreSet.has(oneReference.id)) { + continue; } + newDecorations.push({ + range: oneReference.range, + options: DecorationsManager.DecorationOptions + }); + newDecorationsActualIndex.push(i); + } - const decorations = accessor.deltaDecorations([], newDecorations); - for (let i = 0; i < decorations.length; i++) { - this._decorations.set(decorations[i], reference.children[newDecorationsActualIndex[i]]); - } - }); + const decorations = this._editor.deltaDecorations([], newDecorations); + for (let i = 0; i < decorations.length; i++) { + this._decorations.set(decorations[i], reference.children[newDecorationsActualIndex[i]]); + } } private _onDecorationChanged(): void { @@ -143,21 +140,19 @@ class DecorationsManager implements IDisposable { } }); - this._editor.changeDecorations((accessor) => { - for (let i = 0, len = toRemove.length; i < len; i++) { - this._decorations.delete(toRemove[i]); - } - accessor.deltaDecorations(toRemove, []); - }); + for (let i = 0, len = toRemove.length; i < len; i++) { + this._decorations.delete(toRemove[i]); + } + this._editor.deltaDecorations(toRemove, []); } public removeDecorations(): void { - this._editor.changeDecorations(accessor => { - this._decorations.forEach((value, key) => { - accessor.removeDecoration(key); - }); - this._decorations.clear(); + let toRemove: string[] = []; + this._decorations.forEach((value, key) => { + toRemove.push(key); }); + this._editor.deltaDecorations(toRemove, []); + this._decorations.clear(); } } diff --git a/src/vs/editor/contrib/snippet/snippetSession.ts b/src/vs/editor/contrib/snippet/snippetSession.ts index 218e5ec9fd5543c0d6188fbed2487023e2f36251..a101e5e16bb8138ed4762cd23bdc20cc7ed687e4 100644 --- a/src/vs/editor/contrib/snippet/snippetSession.ts +++ b/src/vs/editor/contrib/snippet/snippetSession.ts @@ -50,7 +50,9 @@ export class OneSnippet { dispose(): void { if (this._placeholderDecorations) { - this._editor.changeDecorations(accessor => this._placeholderDecorations.forEach(handle => accessor.removeDecoration(handle))); + let toRemove: string[] = []; + this._placeholderDecorations.forEach(handle => toRemove.push(handle)); + this._editor.deltaDecorations(toRemove, []); } this._placeholderGroups.length = 0; } diff --git a/src/vs/editor/standalone/browser/quickOpen/editorQuickOpen.ts b/src/vs/editor/standalone/browser/quickOpen/editorQuickOpen.ts index 8d1bce53f7ba59b541938a2df690118875c3a7bf..8bd223b6a2f62169ce3b8b84a41b993c5d611133 100644 --- a/src/vs/editor/standalone/browser/quickOpen/editorQuickOpen.ts +++ b/src/vs/editor/standalone/browser/quickOpen/editorQuickOpen.ts @@ -14,7 +14,7 @@ import { registerEditorContribution, IActionOptions, EditorAction } from 'vs/edi import { IThemeService } from 'vs/platform/theme/common/themeService'; import { Range } from 'vs/editor/common/core/range'; import { ModelDecorationOptions } from 'vs/editor/common/model/textModel'; -import { IModelDecorationsChangeAccessor, IModelDeltaDecoration } from 'vs/editor/common/model'; +import { IModelDeltaDecoration } from 'vs/editor/common/model'; export interface IQuickOpenControllerOpts { inputAriaLabel: string; @@ -100,31 +100,27 @@ export class QuickOpenController implements editorCommon.IEditorContribution, ID }); public decorateLine(range: Range, editor: ICodeEditor): void { - editor.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => { - const oldDecorations: string[] = []; - if (this.rangeHighlightDecorationId) { - oldDecorations.push(this.rangeHighlightDecorationId); - this.rangeHighlightDecorationId = null; - } + const oldDecorations: string[] = []; + if (this.rangeHighlightDecorationId) { + oldDecorations.push(this.rangeHighlightDecorationId); + this.rangeHighlightDecorationId = null; + } - const newDecorations: IModelDeltaDecoration[] = [ - { - range: range, - options: QuickOpenController._RANGE_HIGHLIGHT_DECORATION - } - ]; + const newDecorations: IModelDeltaDecoration[] = [ + { + range: range, + options: QuickOpenController._RANGE_HIGHLIGHT_DECORATION + } + ]; - const decorations = changeAccessor.deltaDecorations(oldDecorations, newDecorations); - this.rangeHighlightDecorationId = decorations[0]; - }); + const decorations = editor.deltaDecorations(oldDecorations, newDecorations); + this.rangeHighlightDecorationId = decorations[0]; } public clearDecorations(): void { if (this.rangeHighlightDecorationId) { - this.editor.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => { - changeAccessor.deltaDecorations([this.rangeHighlightDecorationId], []); - this.rangeHighlightDecorationId = null; - }); + this.editor.deltaDecorations([this.rangeHighlightDecorationId], []); + this.rangeHighlightDecorationId = null; } } } diff --git a/src/vs/workbench/parts/debug/electron-browser/debugHover.ts b/src/vs/workbench/parts/debug/electron-browser/debugHover.ts index e6248b7f74e8479cf2d2c2aa4adfb939badb7b6a..c91609db06ae03c7c9d95846cd6b89136ffd8375 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugHover.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugHover.ts @@ -27,6 +27,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService'; import { editorHoverBackground, editorHoverBorder } from 'vs/platform/theme/common/colorRegistry'; import { WorkbenchTree, WorkbenchTreeController } from 'vs/platform/list/browser/listService'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { ModelDecorationOptions } from 'vs/editor/common/model/textModel'; const $ = dom.$; const MAX_ELEMENTS_SHOWN = 18; @@ -208,15 +209,17 @@ export class DebugHoverWidget implements IContentWidget { this.highlightDecorations = this.editor.deltaDecorations(this.highlightDecorations, [{ range: new Range(pos.lineNumber, expressionRange.startColumn, pos.lineNumber, expressionRange.startColumn + matchingExpression.length), - options: { - className: 'hoverHighlight' - } + options: DebugHoverWidget._HOVER_HIGHLIGHT_DECORATION_OPTIONS }]); return this.doShow(pos, expression, focus); }); } + private static _HOVER_HIGHLIGHT_DECORATION_OPTIONS = ModelDecorationOptions.register({ + className: 'hoverHighlight' + }); + private doFindExpression(container: IExpressionContainer, namesToFind: string[]): TPromise { if (!container) { return TPromise.as(null); diff --git a/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts b/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts index 6f134ab7bc9dc42ce872ccbf037fedf97b789722..f033c84ab3e27ca6e9c399056416f5457afb0ed2 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts @@ -890,13 +890,15 @@ export class FilteredMatchesRenderer extends Disposable implements HiddenAreasPr private createDecoration(range: IRange, model: ITextModel): IModelDeltaDecoration { return { range, - options: { - stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, - className: 'findMatch' - } + options: FilteredMatchesRenderer._FIND_MATCH }; } + private static readonly _FIND_MATCH = ModelDecorationOptions.register({ + stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, + className: 'findMatch' + }); + private computeHiddenRanges(filteredGroups: ISettingsGroup[], allSettingsGroups: ISettingsGroup[], model: ITextModel): IRange[] { // Hide the contents of hidden groups const notMatchesRanges: IRange[] = [];