Avoid losing chat input after accidentally navigating history (#205977)

Fix microsoft/vscode-copilot-release#661
This commit is contained in:
Rob Lourens 2024-02-22 14:03:19 +00:00 committed by GitHub
parent fa7b64426e
commit 71b0a729fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -86,6 +86,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
private historyNavigationBackwardsEnablement!: IContextKey<boolean>;
private historyNavigationForewardsEnablement!: IContextKey<boolean>;
private onHistoryEntry = false;
private inHistoryNavigation = false;
private inputModel: ITextModel | undefined;
private inputEditorHasText: IContextKey<boolean>;
private chatCursorAtTop: IContextKey<boolean>;
@ -160,7 +161,11 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
this.onHistoryEntry = previous || this.history.current() !== null;
aria.status(historyEntry.text);
this.inHistoryNavigation = true;
this.setValue(historyEntry.text);
this.inHistoryNavigation = false;
this._onDidLoadInputState.fire(historyEntry.state);
if (previous) {
this._inputEditor.setPosition({ lineNumber: 1, column: 1 });
@ -269,6 +274,12 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
const model = this._inputEditor.getModel();
const inputHasText = !!model && model.getValueLength() > 0;
this.inputEditorHasText.set(inputHasText);
// If the user is typing on a history entry, then reset the onHistoryEntry flag so that history navigation can be disabled
if (!this.inHistoryNavigation) {
this.onHistoryEntry = false;
}
if (!this.onHistoryEntry) {
this.historyNavigationForewardsEnablement.set(!inputHasText);
this.historyNavigationBackwardsEnablement.set(!inputHasText);