Skip to content

Commit 3268d1d

Browse files
authored
Fix hover highlight range flickering (#151235) (#153038)
1 parent 556d6aa commit 3268d1d

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/vs/editor/contrib/hover/browser/contentHover.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export class ContentHoverController extends Disposable {
3131

3232
private readonly _participants: IEditorHoverParticipant[];
3333
private readonly _widget = this._register(this._instantiationService.createInstance(ContentHoverWidget, this._editor));
34-
private readonly _decorations = this._editor.createDecorationsCollection();
3534
private readonly _computer: ContentHoverComputer;
3635
private readonly _hoverOperation: HoverOperation<IHoverPart>;
3736

3837
private _messages: IHoverPart[];
3938
private _messagesAreComplete: boolean;
39+
private _isChangingDecorations: boolean = false;
4040

4141
constructor(
4242
private readonly _editor: ICodeEditor,
@@ -61,7 +61,12 @@ export class ContentHoverController extends Disposable {
6161
this._register(this._hoverOperation.onResult((result) => {
6262
this._withResult(result.value, result.isComplete, result.hasLoadingMessage);
6363
}));
64-
this._register(this._decorations.onDidChange(() => this._onModelDecorationsChanged()));
64+
this._register(this._editor.onDidChangeModelDecorations(() => {
65+
if (this._isChangingDecorations) {
66+
return;
67+
}
68+
this._onModelDecorationsChanged();
69+
}));
6570
this._register(dom.addStandardDisposableListener(this._widget.getDomNode(), 'keydown', (e) => {
6671
if (e.equals(KeyCode.Escape)) {
6772
this.hide();
@@ -225,12 +230,23 @@ export class ContentHoverController extends Disposable {
225230

226231
if (fragment.hasChildNodes()) {
227232
if (highlightRange) {
228-
this._decorations.set([{
229-
range: highlightRange,
230-
options: ContentHoverController._DECORATION_OPTIONS
231-
}]);
233+
const highlightDecoration = this._editor.createDecorationsCollection();
234+
try {
235+
this._isChangingDecorations = true;
236+
highlightDecoration.set([{
237+
range: highlightRange,
238+
options: ContentHoverController._DECORATION_OPTIONS
239+
}]);
240+
} finally {
241+
this._isChangingDecorations = false;
242+
}
232243
disposables.add(toDisposable(() => {
233-
this._decorations.clear();
244+
try {
245+
this._isChangingDecorations = true;
246+
highlightDecoration.clear();
247+
} finally {
248+
this._isChangingDecorations = false;
249+
}
234250
}));
235251
}
236252

0 commit comments

Comments
 (0)