@@ -45,6 +45,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
45
45
import { basename , extname } from 'vs/base/common/resources' ;
46
46
import { hash } from 'vs/base/common/hash' ;
47
47
import { WindowIdleValue , getWindow } from 'vs/base/browser/dom' ;
48
+ import { ModelDecorationOptions } from 'vs/editor/common/model/textModel' ;
48
49
49
50
// sticky suggest widget which doesn't disappear on focus out and such
50
51
const _sticky = false
@@ -53,7 +54,12 @@ const _sticky = false
53
54
54
55
class LineSuffix {
55
56
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 ;
57
63
58
64
constructor ( private readonly _model : ITextModel , private readonly _position : IPosition ) {
59
65
// spy on what's happening right of the cursor. two cases:
@@ -63,16 +69,21 @@ class LineSuffix {
63
69
if ( maxColumn !== _position . column ) {
64
70
const offset = _model . getOffsetAt ( _position ) ;
65
71
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
+ } ) ;
70
78
}
71
79
}
72
80
73
81
dispose ( ) : void {
74
82
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
+ } ) ;
76
87
}
77
88
}
78
89
@@ -84,7 +95,7 @@ class LineSuffix {
84
95
// read the marker (in case suggest was triggered at line end) or compare
85
96
// the cursor to the line end.
86
97
if ( this . _marker ) {
87
- const range = this . _model . getDecorationRange ( this . _marker [ 0 ] ) ;
98
+ const range = this . _model . getDecorationRange ( this . _marker ) ;
88
99
const end = this . _model . getOffsetAt ( range ! . getStartPosition ( ) ) ;
89
100
return end - this . _model . getOffsetAt ( position ) ;
90
101
} else {
0 commit comments