Skip to content

Commit

Permalink
do not auto finish session when inline chat widgets have focus
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 7, 2023
1 parent 380636e commit aa3e6e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export abstract class EditModeStrategy {
abstract renderChanges(response: EditResponse): Promise<void>;

abstract toggleDiff(): void;

abstract hasFocus(): boolean;
}

export class PreviewStrategy extends EditModeStrategy {
Expand Down Expand Up @@ -128,6 +130,10 @@ export class PreviewStrategy extends EditModeStrategy {
toggleDiff(): void {
// nothing to do
}

hasFocus(): boolean {
return this._widget.hasFocus();
}
}

class InlineDiffDecorations {
Expand Down Expand Up @@ -331,6 +337,10 @@ export class LiveStrategy extends EditModeStrategy {
}
this._widget.updateStatus(message);
}

hasFocus(): boolean {
return this._widget.hasFocus();
}
}

export class LivePreviewStrategy extends LiveStrategy {
Expand Down Expand Up @@ -389,6 +399,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/interactiveEditor/common/interactiveEditor';
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';
Expand Down Expand Up @@ -502,6 +502,10 @@ export class InteractiveEditorWidget {
this._inputEditor.focus();
}

hasFocus() {
return this.domNode.contains(getActiveElement());
}

updateMarkdownMessageExpansionState(expand: boolean) {
this._ctxMessageCropState.set(expand ? 'expanded' : 'cropped');
this._elements.message.style.webkitLineClamp = expand ? '10' : '3';
Expand Down

0 comments on commit aa3e6e8

Please sign in to comment.