Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always scroll down and focus the input #183557

Merged
merged 1 commit into from May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/vs/workbench/contrib/chat/browser/chatWidget.ts
Expand Up @@ -348,10 +348,14 @@ export class ChatWidget extends Disposable implements IChatWidget {

this.container.setAttribute('data-session-id', model.sessionId);
this.viewModel = this.instantiationService.createInstance(ChatViewModel, model);
this.viewModelDisposables.add(this.viewModel.onDidChange(() => {
this.viewModelDisposables.add(this.viewModel.onDidChange(e => {
this.slashCommandsPromise = undefined;
this.requestInProgress.set(this.viewModel!.requestInProgress);
this.onDidChangeItems();
if (e?.kind === 'addRequest') {
revealLastElement(this.tree);
this.focusInput();
}
}));
this.viewModelDisposables.add(this.viewModel.onDidDisposeModel(() => {
// Disposes the viewmodel and listeners
Expand Down Expand Up @@ -380,7 +384,6 @@ export class ChatWidget extends Disposable implements IChatWidget {
const input = query ?? editorValue;
const result = await this.chatService.sendRequest(this.viewModel.sessionId, input);
if (result) {
revealLastElement(this.tree);
this.inputPart.acceptInput(query);
result.responseCompletePromise.then(() => {
const responses = this.viewModel?.getItems().filter(isResponseVM);
Expand Down
17 changes: 11 additions & 6 deletions src/vs/workbench/contrib/chat/common/chatViewModel.ts
Expand Up @@ -19,19 +19,25 @@ export function isRequestVM(item: unknown): item is IChatRequestViewModel {
}

export function isResponseVM(item: unknown): item is IChatResponseViewModel {
return !!item && typeof (item as IChatResponseViewModel).onDidChange !== 'undefined';
return !!item && typeof (item as IChatResponseViewModel).setVote !== 'undefined';
}

export function isWelcomeVM(item: unknown): item is IChatWelcomeMessageViewModel {
return !!item && typeof item === 'object' && 'content' in item;
}

export type IChatViewModelChangeEvent = IChatAddRequestEvent | null;

export interface IChatAddRequestEvent {
kind: 'addRequest';
}

export interface IChatViewModel {
readonly isInitialized: boolean;
readonly providerId: string;
readonly sessionId: string;
readonly onDidDisposeModel: Event<void>;
readonly onDidChange: Event<void>;
readonly onDidChange: Event<IChatViewModelChangeEvent>;
readonly requestInProgress: boolean;
readonly inputPlaceholder?: string;
getItems(): (IChatRequestViewModel | IChatResponseViewModel | IChatWelcomeMessageViewModel)[];
Expand Down Expand Up @@ -64,7 +70,6 @@ export interface IChatLiveUpdateData {
}

export interface IChatResponseViewModel {
readonly onDidChange: Event<void>;
readonly id: string;
readonly sessionId: string;
/** This ID updates every time the underlying data changes */
Expand All @@ -91,7 +96,7 @@ export class ChatViewModel extends Disposable implements IChatViewModel {
private readonly _onDidDisposeModel = this._register(new Emitter<void>());
readonly onDidDisposeModel = this._onDidDisposeModel.event;

private readonly _onDidChange = this._register(new Emitter<void>());
private readonly _onDidChange = this._register(new Emitter<IChatViewModelChangeEvent>());
readonly onDidChange = this._onDidChange.event;

private readonly _items: (ChatRequestViewModel | ChatResponseViewModel)[] = [];
Expand Down Expand Up @@ -154,13 +159,13 @@ export class ChatViewModel extends Disposable implements IChatViewModel {
}
}

this._onDidChange.fire();
this._onDidChange.fire(e.kind === 'addRequest' ? { kind: 'addRequest' } : null);
}));
}

private onAddResponse(responseModel: IChatResponseModel) {
const response = this.instantiationService.createInstance(ChatResponseViewModel, responseModel);
this._register(response.onDidChange(() => this._onDidChange.fire()));
this._register(response.onDidChange(() => this._onDidChange.fire(null)));
this._items.push(response);
}

Expand Down