mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Always scroll down and focus the input (#183557)
This commit is contained in:
parent
230a6266eb
commit
f104f9bd62
|
@ -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
|
||||
|
@ -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);
|
||||
|
|
|
@ -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)[];
|
||||
|
@ -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 */
|
||||
|
@ -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)[] = [];
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue