Skip to content

Commit b70a276

Browse files
authored
1 parent 7bf0f1c commit b70a276

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/vs/editor/contrib/suggest/browser/suggestController.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4545
import { basename, extname } from 'vs/base/common/resources';
4646
import { hash } from 'vs/base/common/hash';
4747
import { WindowIdleValue, getWindow } from 'vs/base/browser/dom';
48+
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
4849

4950
// sticky suggest widget which doesn't disappear on focus out and such
5051
const _sticky = false
@@ -53,7 +54,12 @@ const _sticky = false
5354

5455
class LineSuffix {
5556

56-
private readonly _marker: string[] | undefined;
57+
private readonly _decorationOptions = ModelDecorationOptions.register({
58+
description: 'suggest-line-suffix',
59+
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges
60+
});
61+
62+
private _marker: string | undefined;
5763

5864
constructor(private readonly _model: ITextModel, private readonly _position: IPosition) {
5965
// spy on what's happening right of the cursor. two cases:
@@ -63,16 +69,21 @@ class LineSuffix {
6369
if (maxColumn !== _position.column) {
6470
const offset = _model.getOffsetAt(_position);
6571
const end = _model.getPositionAt(offset + 1);
66-
this._marker = _model.deltaDecorations([], [{
67-
range: Range.fromPositions(_position, end),
68-
options: { description: 'suggest-line-suffix', stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges }
69-
}]);
72+
_model.changeDecorations(accessor => {
73+
if (this._marker) {
74+
accessor.removeDecoration(this._marker);
75+
}
76+
this._marker = accessor.addDecoration(Range.fromPositions(_position, end), this._decorationOptions);
77+
});
7078
}
7179
}
7280

7381
dispose(): void {
7482
if (this._marker && !this._model.isDisposed()) {
75-
this._model.deltaDecorations(this._marker, []);
83+
this._model.changeDecorations(accessor => {
84+
accessor.removeDecoration(this._marker!);
85+
this._marker = undefined;
86+
});
7687
}
7788
}
7889

@@ -84,7 +95,7 @@ class LineSuffix {
8495
// read the marker (in case suggest was triggered at line end) or compare
8596
// the cursor to the line end.
8697
if (this._marker) {
87-
const range = this._model.getDecorationRange(this._marker[0]);
98+
const range = this._model.getDecorationRange(this._marker);
8899
const end = this._model.getOffsetAt(range!.getStartPosition());
89100
return end - this._model.getOffsetAt(position);
90101
} else {

0 commit comments

Comments
 (0)