Skip to content

Commit 3088f23

Browse files
authored
reset context keys on reset/hide (microsoft#184042)
fixes microsoft/vscode-internalbacklog#4330
1 parent 8a76ae4 commit 3088f23

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ export class InteractiveEditorWidget {
158158
private readonly _inputModel: ITextModel;
159159
private readonly _ctxInputEmpty: IContextKey<boolean>;
160160
private readonly _ctxMessageCropState: IContextKey<'cropped' | 'not_cropped' | 'expanded'>;
161+
private readonly _ctxInnerCursorFirst: IContextKey<boolean>;
162+
private readonly _ctxInnerCursorLast: IContextKey<boolean>;
163+
private readonly _ctxInputEditorFocused: IContextKey<boolean>;
161164

162165
private readonly _progressBar: ProgressBar;
163166

@@ -219,27 +222,32 @@ export class InteractiveEditorWidget {
219222
this._ctxMessageCropState = CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE.bindTo(this._contextKeyService);
220223
this._ctxInputEmpty = CTX_INTERACTIVE_EDITOR_EMPTY.bindTo(this._contextKeyService);
221224

222-
const ctxInnerCursorFirst = CTX_INTERACTIVE_EDITOR_INNER_CURSOR_FIRST.bindTo(this._contextKeyService);
223-
const ctxInnerCursorLast = CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST.bindTo(this._contextKeyService);
224-
const ctxInputEditorFocused = CTX_INTERACTIVE_EDITOR_FOCUSED.bindTo(this._contextKeyService);
225+
this._ctxInnerCursorFirst = CTX_INTERACTIVE_EDITOR_INNER_CURSOR_FIRST.bindTo(this._contextKeyService);
226+
this._ctxInnerCursorLast = CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST.bindTo(this._contextKeyService);
227+
this._ctxInputEditorFocused = CTX_INTERACTIVE_EDITOR_FOCUSED.bindTo(this._contextKeyService);
225228

226229
// (1) inner cursor position (last/first line selected)
227230
const updateInnerCursorFirstLast = () => {
228231
const { lineNumber } = this._inputEditor.getPosition();
229-
ctxInnerCursorFirst.set(lineNumber === 1);
230-
ctxInnerCursorLast.set(lineNumber === this._inputModel.getLineCount());
232+
this._ctxInnerCursorFirst.set(lineNumber === 1);
233+
this._ctxInnerCursorLast.set(lineNumber === this._inputModel.getLineCount());
231234
};
232235
this._store.add(this._inputEditor.onDidChangeCursorPosition(updateInnerCursorFirstLast));
233236
updateInnerCursorFirstLast();
234237

235238
// (2) input editor focused or not
236239
const updateFocused = () => {
237240
const hasFocus = this._inputEditor.hasWidgetFocus();
238-
ctxInputEditorFocused.set(hasFocus);
241+
this._ctxInputEditorFocused.set(hasFocus);
239242
this._elements.content.classList.toggle('synthetic-focus', hasFocus);
240243
};
241244
this._store.add(this._inputEditor.onDidFocusEditorWidget(updateFocused));
242245
this._store.add(this._inputEditor.onDidBlurEditorWidget(updateFocused));
246+
this._store.add(toDisposable(() => {
247+
this._ctxInnerCursorFirst.reset();
248+
this._ctxInnerCursorLast.reset();
249+
this._ctxInputEditorFocused.reset();
250+
}));
243251
updateFocused();
244252

245253
// placeholder
@@ -474,6 +482,10 @@ export class InteractiveEditorWidget {
474482

475483
reset() {
476484
this._ctxInputEmpty.reset();
485+
this._ctxInnerCursorFirst.reset();
486+
this._ctxInnerCursorLast.reset();
487+
this._ctxInputEditorFocused.reset();
488+
477489
this.value = '';
478490
this.updateMarkdownMessage(undefined);
479491

0 commit comments

Comments
 (0)