Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken authored Dec 12, 2023
1 parent 7bf0f1c commit b70a276
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/vs/editor/contrib/suggest/browser/suggestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { basename, extname } from 'vs/base/common/resources';
import { hash } from 'vs/base/common/hash';
import { WindowIdleValue, getWindow } from 'vs/base/browser/dom';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';

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

class LineSuffix {

private readonly _marker: string[] | undefined;
private readonly _decorationOptions = ModelDecorationOptions.register({
description: 'suggest-line-suffix',
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges
});

private _marker: string | undefined;

constructor(private readonly _model: ITextModel, private readonly _position: IPosition) {
// spy on what's happening right of the cursor. two cases:
Expand All @@ -63,16 +69,21 @@ class LineSuffix {
if (maxColumn !== _position.column) {
const offset = _model.getOffsetAt(_position);
const end = _model.getPositionAt(offset + 1);
this._marker = _model.deltaDecorations([], [{
range: Range.fromPositions(_position, end),
options: { description: 'suggest-line-suffix', stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges }
}]);
_model.changeDecorations(accessor => {
if (this._marker) {
accessor.removeDecoration(this._marker);
}
this._marker = accessor.addDecoration(Range.fromPositions(_position, end), this._decorationOptions);
});
}
}

dispose(): void {
if (this._marker && !this._model.isDisposed()) {
this._model.deltaDecorations(this._marker, []);
this._model.changeDecorations(accessor => {
accessor.removeDecoration(this._marker!);
this._marker = undefined;
});
}
}

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

0 comments on commit b70a276

Please sign in to comment.