do not auto finish session when inline chat widgets have focus (#184492)

* do not auto finish session when inline chat widgets have focus

re https://github.com/microsoft/vscode-internalbacklog/issues/4354

* fix compile errors caused by new base method
This commit is contained in:
Johannes Rieken
2023-06-07 15:29:10 +02:00
committed by GitHub
parent bb6d7d67ff
commit 3ccf16ef21
6 changed files with 26 additions and 4 deletions
@@ -307,6 +307,10 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider {
return range.getStartPosition();
}
hasFocus() {
return this.domNode.contains(dom.getActiveElement());
}
protected _isShowing: boolean = false;
show(rangeOrPos: IRange | IPosition, heightInLines: number): void {
@@ -122,7 +122,7 @@ export class ExceptionWidget extends ZoneWidget {
this.container?.focus();
}
hasFocus(): boolean {
override hasFocus(): boolean {
return dom.isAncestor(document.activeElement, this.container);
}
}
@@ -281,7 +281,7 @@ export class InteractiveEditorController implements IEditorContribution {
}));
this._sessionStore.add(this._editor.onDidChangeModelContent(e => {
if (this._ignoreModelContentChanged) {
if (this._ignoreModelContentChanged || this._strategy?.hasFocus()) {
return;
}
@@ -40,6 +40,8 @@ export abstract class EditModeStrategy {
abstract renderChanges(response: EditResponse): Promise<void>;
abstract toggleDiff(): void;
abstract hasFocus(): boolean;
}
export class PreviewStrategy extends EditModeStrategy {
@@ -126,6 +128,10 @@ export class PreviewStrategy extends EditModeStrategy {
toggleDiff(): void {
// nothing to do
}
hasFocus(): boolean {
return this._widget.hasFocus();
}
}
class InlineDiffDecorations {
@@ -318,6 +324,10 @@ export class LiveStrategy extends EditModeStrategy {
}
this._widget.updateStatus(message);
}
hasFocus(): boolean {
return this._widget.hasFocus();
}
}
export class LivePreviewStrategy extends LiveStrategy {
@@ -372,6 +382,10 @@ export class LivePreviewStrategy extends LiveStrategy {
}
scrollState.restore(this._editor);
}
override hasFocus(): boolean {
return super.hasFocus() || this._diffZone.hasFocus() || this._previewZone.hasFocus();
}
}
function showSingleCreateFile(accessor: ServicesAccessor, edit: EditResponse) {
@@ -14,7 +14,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { ZoneWidget } from 'vs/editor/contrib/zoneWidget/browser/zoneWidget';
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';
import { IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
import { Dimension, addDisposableListener, getTotalHeight, getTotalWidth, h, reset } from 'vs/base/browser/dom';
import { Dimension, addDisposableListener, getActiveElement, getTotalHeight, getTotalWidth, h, reset } from 'vs/base/browser/dom';
import { Emitter, Event, MicrotaskEmitter } from 'vs/base/common/event';
import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration';
import { ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget';
@@ -553,6 +553,10 @@ export class InteractiveEditorWidget {
this._inputEditor.focus();
}
hasFocus() {
return this.domNode.contains(getActiveElement());
}
// --- preview
showEditsPreview(textModelv0: ITextModel, edits: ISingleEditOperation[], changes: readonly LineRangeMapping[]) {
@@ -467,7 +467,7 @@ class DirtyDiffWidget extends PeekViewWidget {
this.editor.revealLineInCenterIfOutsideViewport(range.endLineNumber, ScrollType.Smooth);
}
hasFocus(): boolean {
override hasFocus(): boolean {
return this.diffEditor.hasTextFocus();
}