Skip to content

Commit 3ccf16e

Browse files
authored
do not auto finish session when inline chat widgets have focus (microsoft#184492)
* do not auto finish session when inline chat widgets have focus re microsoft/vscode-internalbacklog#4354 * fix compile errors caused by new base method
1 parent bb6d7d6 commit 3ccf16e

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider {
307307
return range.getStartPosition();
308308
}
309309

310+
hasFocus() {
311+
return this.domNode.contains(dom.getActiveElement());
312+
}
313+
310314
protected _isShowing: boolean = false;
311315

312316
show(rangeOrPos: IRange | IPosition, heightInLines: number): void {

src/vs/workbench/contrib/debug/browser/exceptionWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class ExceptionWidget extends ZoneWidget {
122122
this.container?.focus();
123123
}
124124

125-
hasFocus(): boolean {
125+
override hasFocus(): boolean {
126126
return dom.isAncestor(document.activeElement, this.container);
127127
}
128128
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export class InteractiveEditorController implements IEditorContribution {
281281
}));
282282

283283
this._sessionStore.add(this._editor.onDidChangeModelContent(e => {
284-
if (this._ignoreModelContentChanged) {
284+
if (this._ignoreModelContentChanged || this._strategy?.hasFocus()) {
285285
return;
286286
}
287287

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export abstract class EditModeStrategy {
4040
abstract renderChanges(response: EditResponse): Promise<void>;
4141

4242
abstract toggleDiff(): void;
43+
44+
abstract hasFocus(): boolean;
4345
}
4446

4547
export class PreviewStrategy extends EditModeStrategy {
@@ -126,6 +128,10 @@ export class PreviewStrategy extends EditModeStrategy {
126128
toggleDiff(): void {
127129
// nothing to do
128130
}
131+
132+
hasFocus(): boolean {
133+
return this._widget.hasFocus();
134+
}
129135
}
130136

131137
class InlineDiffDecorations {
@@ -318,6 +324,10 @@ export class LiveStrategy extends EditModeStrategy {
318324
}
319325
this._widget.updateStatus(message);
320326
}
327+
328+
hasFocus(): boolean {
329+
return this._widget.hasFocus();
330+
}
321331
}
322332

323333
export class LivePreviewStrategy extends LiveStrategy {
@@ -372,6 +382,10 @@ export class LivePreviewStrategy extends LiveStrategy {
372382
}
373383
scrollState.restore(this._editor);
374384
}
385+
386+
override hasFocus(): boolean {
387+
return super.hasFocus() || this._diffZone.hasFocus() || this._previewZone.hasFocus();
388+
}
375389
}
376390

377391
function showSingleCreateFile(accessor: ServicesAccessor, edit: EditResponse) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
1414
import { ZoneWidget } from 'vs/editor/contrib/zoneWidget/browser/zoneWidget';
1515
import { CTX_INTERACTIVE_EDITOR_FOCUSED, CTX_INTERACTIVE_EDITOR_INNER_CURSOR_FIRST, CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST, CTX_INTERACTIVE_EDITOR_EMPTY, CTX_INTERACTIVE_EDITOR_OUTER_CURSOR_POSITION, CTX_INTERACTIVE_EDITOR_VISIBLE, MENU_INTERACTIVE_EDITOR_WIDGET, MENU_INTERACTIVE_EDITOR_WIDGET_STATUS, MENU_INTERACTIVE_EDITOR_WIDGET_MARKDOWN_MESSAGE, CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE, IInteractiveEditorSlashCommand, MENU_INTERACTIVE_EDITOR_WIDGET_FEEDBACK, ACTION_ACCEPT_CHANGES } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
1616
import { IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
17-
import { Dimension, addDisposableListener, getTotalHeight, getTotalWidth, h, reset } from 'vs/base/browser/dom';
17+
import { Dimension, addDisposableListener, getActiveElement, getTotalHeight, getTotalWidth, h, reset } from 'vs/base/browser/dom';
1818
import { Emitter, Event, MicrotaskEmitter } from 'vs/base/common/event';
1919
import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration';
2020
import { ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget';
@@ -553,6 +553,10 @@ export class InteractiveEditorWidget {
553553
this._inputEditor.focus();
554554
}
555555

556+
hasFocus() {
557+
return this.domNode.contains(getActiveElement());
558+
}
559+
556560
// --- preview
557561

558562
showEditsPreview(textModelv0: ITextModel, edits: ISingleEditOperation[], changes: readonly LineRangeMapping[]) {

src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class DirtyDiffWidget extends PeekViewWidget {
467467
this.editor.revealLineInCenterIfOutsideViewport(range.endLineNumber, ScrollType.Smooth);
468468
}
469469

470-
hasFocus(): boolean {
470+
override hasFocus(): boolean {
471471
return this.diffEditor.hasTextFocus();
472472
}
473473

0 commit comments

Comments
 (0)