From 34e74ba1578fe105afc8ca26615f45f9397bdd96 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 20 Oct 2017 09:38:09 +0200 Subject: [PATCH] Tweak the way find decorations are managed --- .../contrib/find/common/findDecorations.ts | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/vs/editor/contrib/find/common/findDecorations.ts b/src/vs/editor/contrib/find/common/findDecorations.ts index 4a59a7b7e56..20db13e30ca 100644 --- a/src/vs/editor/contrib/find/common/findDecorations.ts +++ b/src/vs/editor/contrib/find/common/findDecorations.ts @@ -132,29 +132,32 @@ export class FindDecorations implements IDisposable { } public set(findMatches: editorCommon.FindMatch[], findScope: Range): void { - let newDecorations: editorCommon.IModelDeltaDecoration[] = new Array(findMatches.length); - for (let i = 0, len = findMatches.length; i < len; i++) { - newDecorations[i] = { - range: findMatches[i].range, - options: FindDecorations._FIND_MATCH_DECORATION - }; - } - if (findScope) { - newDecorations.unshift({ - range: findScope, - options: FindDecorations._FIND_SCOPE_DECORATION - }); - } - let tmpDecorations = this._editor.deltaDecorations(this._allDecorations(), newDecorations); + this._editor.changeDecorations((accessor) => { + // Find matches + let newFindMatchesDecorations: editorCommon.IModelDeltaDecoration[] = new Array(findMatches.length); + for (let i = 0, len = findMatches.length; i < len; i++) { + newFindMatchesDecorations[i] = { + range: findMatches[i].range, + options: FindDecorations._FIND_MATCH_DECORATION + }; + } + this._decorations = accessor.deltaDecorations(this._decorations, newFindMatchesDecorations); - if (findScope) { - this._findScopeDecorationId = tmpDecorations.shift(); - } else { - this._findScopeDecorationId = null; - } - this._decorations = tmpDecorations; - this._rangeHighlightDecorationId = null; - this._highlightedDecorationId = null; + // Range highlight + if (this._rangeHighlightDecorationId) { + accessor.removeDecoration(this._rangeHighlightDecorationId); + this._rangeHighlightDecorationId = null; + } + + // Find scope + if (this._findScopeDecorationId) { + accessor.removeDecoration(this._findScopeDecorationId); + this._findScopeDecorationId = null; + } + if (findScope) { + this._findScopeDecorationId = accessor.addDecoration(findScope, FindDecorations._FIND_SCOPE_DECORATION); + } + }); } private _allDecorations(): string[] { -- GitLab