Skip to content

Commit 7322bbd

Browse files
authored
update whole range visual decoration after changes are applied (microsoft#185315)
* update whole range visual decoration after changes are applied * fix tests
1 parent 977b6a1 commit 7322bbd

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,16 @@ export class InlineChatController implements IEditorContribution {
292292

293293
this._sessionStore.clear();
294294

295-
const wholeRangeDecoration = this._editor.createDecorationsCollection([{
296-
range: this._activeSession.wholeRange.value,
297-
options: InlineChatController._decoBlock
298-
}]);
295+
const wholeRangeDecoration = this._editor.createDecorationsCollection();
296+
const updateWholeRangeDecoration = () => {
297+
wholeRangeDecoration.set([{
298+
range: this._activeSession!.wholeRange.value,
299+
options: InlineChatController._decoBlock
300+
}]);
301+
};
299302
this._sessionStore.add(toDisposable(() => wholeRangeDecoration.clear()));
303+
this._sessionStore.add(this._activeSession.wholeRange.onDidChange(updateWholeRangeDecoration));
304+
updateWholeRangeDecoration();
300305

301306
this._zone.value.widget.updateSlashCommands(this._activeSession.session.slashCommands ?? []);
302307
this._zone.value.widget.placeholder = this._getPlaceholderText();

src/vs/workbench/contrib/inlineChat/browser/inlineChatSession.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ class SessionWholeRange {
6666

6767
private static readonly _options = { description: 'inlineChat/session/wholeRange' };
6868

69-
private readonly _store = new DisposableStore();
69+
private readonly _onDidChange = new Emitter<this>();
70+
readonly onDidChange: Event<this> = this._onDidChange.event;
71+
7072
private readonly _decorationIds: string[] = [];
7173

7274
constructor(private readonly _textModel: ITextModel, wholeRange: IRange) {
7375
this._decorationIds = _textModel.deltaDecorations([], [{ range: wholeRange, options: SessionWholeRange._options }]);
74-
this._store.add(toDisposable(() => {
75-
if (!_textModel.isDisposed()) {
76-
_textModel.deltaDecorations(this._decorationIds, []);
77-
}
78-
}));
7976
}
8077

8178
dispose() {
82-
this._store.dispose();
79+
this._onDidChange.dispose();
80+
if (!this._textModel.isDisposed()) {
81+
this._textModel.deltaDecorations(this._decorationIds, []);
82+
}
8383
}
8484

8585
trackEdits(edits: ISingleEditOperation[]): void {
@@ -88,6 +88,7 @@ class SessionWholeRange {
8888
newDeco.push({ range: edit.range, options: SessionWholeRange._options });
8989
}
9090
this._decorationIds.push(...this._textModel.deltaDecorations([], newDeco));
91+
this._onDidChange.fire(this);
9192
}
9293

9394
get value(): Range {

0 commit comments

Comments
 (0)